program project1;
var f:array[0..60,0..60] of longint;
t:longint;
procedure init;
begin
assign(input,'piggy.in');reset(input);
assign(output,'piggy.out');rewrite(output);
read(t);
end;
function dfs(n,m:longint):longint;
begin
if f[n,m]>0 then exit(f[n,m]);
if (n=m)or(m=1) then begin f[n,m]:=1;exit(1);end;
f[n,m]:=dfs(n-1,m);
f[n,m]:=f[n,m]*m;
f[n,m]:=f[n,m]+dfs(n-1,m-1);
exit(f[n,m]);
end;
procedure main;
var tt,n,m:longint;
begin
for tt:=1 to t do
begin
read(n,m);
if n<m then writeln(0) else
writeln(dfs(n,m));
end;
close(input);
close(output);
end;
begin
init;
main;
end.