#includelong long int a[21];long long int fun(int n,int m){ int i; long long int sum = 1; m = m>(n-m)?n-m:m; for(i = 1; i <= m; i ++) sum = (sum*(n-m+i))/i; return sum;}int main(){ int i,T,n,m; a[2] = 1; a[3] = 2; for(i = 4;i <= 20;i++) a[i] = (i-1)*(a[i-1]+a[i-2]); scanf("%d",&T); while(T--) { scanf("%d%d",&n,&m); printf("%I64d\n",a[m]*fun(n,n-m)); } return 0;}