var t:array[1..100] of longint;
n,a,b,i:longint;
procedure hnt(a,b:longint);
var k,i,j,o:longint;
begin
for i:=1 to a do
begin
k:=b mod (t[i]*3);
if (k=1) or (k=6) then write(1,' ');
if (k=2) or (k=5) then write(2,' ');
if (k=3) or (k=4) then write(3,' ');
end;
end;
begin
read(n); t[1]:=1;
for i:=2 to 20 do t[i]:=t[i-1]*3;
for i:=1 to n do
begin
read(a,b);
if (b=0) then for i:=1 to a do write(1,' ') else hnt(a,b);
end;
end.
n,a,b,i:longint;
procedure hnt(a,b:longint);
var k,i,j,o:longint;
begin
for i:=1 to a do
begin
k:=b mod (t[i]*3);
if (k=1) or (k=6) then write(1,' ');
if (k=2) or (k=5) then write(2,' ');
if (k=3) or (k=4) then write(3,' ');
end;
end;
begin
read(n); t[1]:=1;
for i:=2 to 20 do t[i]:=t[i-1]*3;
for i:=1 to n do
begin
read(a,b);
if (b=0) then for i:=1 to a do write(1,' ') else hnt(a,b);
end;
end.