#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define rep(i,a,n) for (int i=a;i=a;i--) #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define fi first #define se second #define SZ(x) ((int)(x).size()) #define ACCU accumulate #define TWO(x) (1<<(x)) #define TWOL(x) (1ll<<(x)) #define clr(a) memset(a,0,sizeof(a)) #define POSIN(x,y) (0<=(x)&&(x) VI; typedef vector VS; typedef vector VD; typedef long long ll; typedef long double LD; typedef pair PII; typedef pair PLL; typedef vector VL; typedef vector VPII; typedef complex CD; const int inf=0x20202020; const ll mod=1000000007; const double eps=1e-9; const double pi=3.1415926535897932384626; const int DX[]={1,0,-1,0},DY[]={0,1,0,-1}; ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} // head const int N=(1<<18)+10; ll pd[N],dp[N]; ll ret[20][20]; int c[20]; void solve() { dp[1]=1; ret[1][1]=1; for (int i=1;i<18;i++) { rep(S,0,TWO(i)) pd[S]=dp[S]; rep(S,0,TWO(i+1)) dp[S]=0; rep(S,0,TWO(i)) if (pd[S]) for (int k=0;k<=i;k++) { int tot=0; rep(j,0,i) if (S&TWO(j)) c[tot++]=j; rep(j,0,tot) if (c[j]>=k) c[j]++; bool fg=0; rep(j,0,tot) if (c[j]>k) { c[j]=k;break; fg=1; } if (!fg) c[tot++]=k; int nS=0; rep(j,0,tot) nS|=TWO(c[j]); dp[nS]+=pd[S]; } rep(S,0,TWO(i+1)) ret[i+1][__builtin_popcount(S)]+=dp[S]; } } int _,n,k; int main() { solve(); for (scanf("%d",&_);_;_--) { scanf("%d%d",&n,&k); printf("%I64d\n",ret[n][k]); } }