#include <cstdio>
using namespace std;
#define rep(i, n)       for(int (i)=0; (i)<(int)(n); ++(i))
#define FOR(i, a, b)    for(int (i)=(int)(a); (i)<=(int)(b); ++(i))
typedef unsigned long long LL;
inline LL C(int r,int c) {
	if(c>r-c)	c=r-c;
	LL res=1;
	FOR(i,1,c)
		res=res*(r-i+1)/i;
	return res;
}
int main(int argc, char const *argv[]) {
	int T;	scanf("%d",&T);
	while(T--) {
		int cs,P,r,c;	scanf("%d%d%d%d",&cs,&P,&r,&c);
		int k=r-c;		LL s=1;
		rep(i,k)		s*=P;		
		s*=C(r,c);		
		printf("%d %llu\n",cs,s);
	}	
    return 0;
}

