1 #include<iostream>
2 #include<algorithm>
3 #include<cstdio>
4 #include<cstring>
5 #include<cstdlib>
6 #include<cmath>
7 using namespace std;
8
9 const int ONE=201;
10
11 int T;
12 int n,k;
13 int prime[ONE],cnt;
14 int p[ONE][3];
15 int record,x;
16
17 struct power
18 {
19 int num[10001],len;
20 void print()
21 {
22 for(int i=len;i>=1;i--)
23 printf("%d",num[i]);
24 }
25
26 friend power operator *(power a,power b)
27 {
28 power c;
29 c.len=a.len+b.len;
30 for(int i=1;i<=c.len;i++) c.num[i]=0;
31
32 for(int i=1;i<=a.len;i++)
33 {
34 x=0;
35 for(int j=1;j<=b.len;j++)
36 {
37 c.num[i+j-1]=c.num[i+j-1] + x + a.num[i]*b.num[j];
38 x=c.num[i+j-1]/10;
39 c.num[i+j-1]%=10;
40 }
41 c.num[i+b.len]=x;
42 }
43
44 while(c.len>1 && !c.num[c.len]) c.len--;
45 return c;
46 }
47 }kd[3],pass;
48
49 void dealwith(int x)
50 {
51 for(int i=1;i<=pass.len;i++) pass.num[i]=0;
52 pass.len=0;
53 while(x)
54 {
55 pass.num[++pass.len]=x%10;
56 x/=10;
57 }
58 }
59
60 int get()
61 {
62 int res=1,Q=1;char c;
63 while( (c=getchar())<48 || c>57 )
64 if(c==‘-‘)Q=-1;
65 res=c-48;
66 while( (c=getchar())>=48 && c<=57 )
67 res=res*10+c-48;
68 return res*Q;
69 }
70
71 int PD(int x)
72 {
73 for(int i=2;i<x;i++)
74 if(x%i==0) return 0;
75 return 1;
76 }
77
78 int Chai(int x,int PD)
79 {
80 if(x==1) return x;
81 for(int i=1;i<=cnt;i++)
82 {
83 if(!(x%prime[i]))
84 {
85 p[prime[i]][PD]++;
86 x=Chai(x/prime[i],PD);
87 break;
88 }
89 }
90 return x;
91 }
92
93 int Deal(int x,int m,int PD)
94 {
95 record=1;
96 for(int i=1;i<=m;i++)
97 {
98 record*=x;
99 record=Chai(record,PD);
100 }
101
102 if(PD==1)
103 {
104 record*=(x-m-1);
105 record=Chai(record,PD);
106 }
107
108 p[record][PD]++;
109 }
110
111 int main()
112 {
113 T=get();
114 for(int i=2;i<=200;i++)
115 if(PD(i)) prime[++cnt]=i;
116
117 while(T--)
118 {
119 n=get(); k=get();
120 if(n>k)
121 {
122 printf("0 1\n");
123 continue;
124 }
125
126 memset(p,0,sizeof(p));
127 Deal(k+1,n-1,1); Deal(k,n,2);
128 for(int i=1;i<=200;i++)
129 {
130 int x=min(p[i][1],p[i][2]);
131 p[i][1]-=x; p[i][2]-=x;
132 }
133
134 kd[1].len=kd[2].len=1;
135 kd[1].num[1]=kd[2].num[1]=1;
136 for(int i=1;i<=cnt;i++)
137 {
138 dealwith(prime[i]);
139 for(int t=1;t<=2;t++)
140 for(int j=1;j<=p[prime[i]][t];j++)
141 kd[t]=kd[t]*pass;
142 }
143
144 kd[1].print(); printf(" ");
145 kd[2].print(); printf("\n");
146
147 }
148 }