/*

思路:有n位新郎,但是又m位新郎会找错,那么有n-m位新郎会找对,而找对的n-m位新郎的找发就是在

n位新郎中随机找n-m位有多少种排列组合公式有n!/(m!*(n-m!)),而另外找错的新郎则按照错排公式来做

D(n)=(n-1)*(D(n-1)+D(n-2))

*/

#include<stdio.h>
long long p[] = { ,,, };
long long q[] = { ,,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,- };
long long jiecheng(int n) {
if (p[n] != )
{
return p[n];
}
return p[n] = jiecheng(n - )*n;
} long long recrusion(int n) {
if (q[n] > -) {
return q[n];
}
return q[n] = (n - )*(recrusion(n - ) + recrusion(n - ));
} int main() {
int m;
p[] = ;
p[] = ;
int a, b;
scanf("%d", &m);
for (int i = ; i < m; i++) {
scanf("%d %d", &a, &b);
printf("%lld\n", (jiecheng(a) / (jiecheng(b)*jiecheng(a - b)))*recrusion(b));
}
return ;
}
05-28 22:16