program fall;
var f:array [1..55,1..55] of qword;
t,n,m,i,j,k:longint;
begin
assign(input,'piggy.in');
assign(output,'piggy.out');
reset(input);
rewrite(output);
for i:=1 to 55 do begin f[i,i]:=1; f[i,0]:=0; end;
for j:=1 to 55 do
for i:=j+1 to 55 do
f[i,j]:=f[i-1,j-1]+j*f[i-1,j];
readln(t);
for k:=1 to t do
begin
readln(n,m);
writeln(f[n,m]);
end;
close(input);
close(output);
end.