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