var w:array[0..100000]of longint;
t,i,k:longint;
s:ansistring;
a:qword;
function f(s:ansistring):qword;
var i:longint;
ans:qword;
begin
fillchar(w,sizeof(w),0);
w[0]:=length(s);
ans:=0;
for i:=1 to length(s) do begin
if (s[i]<='9')and(s[i]>='0') then
w[i]:=ord(s[i])-ord('0')
else w[i]:=ord(s[i])-ord('A')+10;
inc(ans,w[i]);
end;
exit(ans);
end;
begin
readln(t);
for i:=1 to t do begin
readln(k);
readln(s);
fillchar(w,sizeof(w),0);
a:=f(s);
// writeln(a);
if a mod (k-1)=0 then writeln('yes')
else writeln('no');
end;
close(input);
close(output);
end.