var
i,j,k,n,m,pp,t:longint;
f:array[1..1000,1..1000] of qword;
p:array[1..55] of qword;
begin
assign(input,'piggy.in');
reset(input);
assign(output,'piggy.out');
rewrite(output);
for i:= 1 to 55 do
f[i,1]:=1;
f[1,1]:=1;
f[2,2]:=2;
for i:=3 to 18 do
begin
for j:= 2 to 17 do
f[i,j]:=(f[i-1,j]+f[i-1,j-1])*j;
end;
p[1]:=1;
for i:=2 to 18 do
p[i]:=p[i-1]*i;
read(t);
for pp:= 1 to t do
begin
read(n,m);
if m=n then
writeln(1)
else
writeln(f[n,m] div p[m]);
end;
close(input);
close(output);
end.