#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int t,n,m;
struct bigint{
static const int B=10000;
int ws,s[1000];
bigint(){ws=1; memset(s,0,sizeof s);}
bigint operator * (const bigint x) const{
bigint ret;
ret.ws=ws+x.ws-1; int jw;
for (int i=1;i<=ws;i++){
jw=0;
for (int j=1;j<=x.ws;j++){
ret.s[i+j-1]+=s[i]*x.s[j]+jw;
jw=ret.s[i+j-1]/B;
ret.s[i+j-1]%=B;
}
if (jw!=0) ret.s[i+x.ws]=jw;
}
if (ret.s[ws+x.ws]) ret.ws=ws+x.ws;
return ret;
}
void operator = (const int x){this->ws=1; this->s[1]=x;}
}fz,fm;
bigint pow(int x,int y){
bigint tmp,ret; tmp=x; ret=1;
while (y){if (y&1) ret=ret*tmp; y>>=1; tmp=tmp*tmp;}
return ret;
}
void print(bigint x){
printf("%d",x.s[x.ws]);
while (--x.ws) printf("%d%d%d%d",x.s[x.ws]/1000,x.s[x.ws]/100%10,x.s[x.ws]/10%10,x.s[x.ws]%10);
}
int gcd(int x,int y){return y==0?x:gcd(y,x%y);}
int main(){
scanf("%d",&t);
while (t--){
scanf("%d%d",&n,&m); if (n>m){puts("0 1"); continue;}
fz=pow(m+1,n-1); fm=1; int p=m+1-n; bigint tmp;
for (int i=1;i<=n;i++){
int g=gcd(m,p); tmp=m/g; fm=fm*tmp; p/=g;
}
tmp=p; fz=fz*tmp;
print(fz); printf(" "); print(fm); puts("");
}
return 0;
}