# [bzoj2339][HNOI2011]卡农


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
#define MAXM 1000010
const int MOD = 100000007;
const int inf = 1<<30;
const double eps = 1e-8;
typedef long long ll;
#define rep(I, S, T) for (int I = S; I <= T; I ++)
#define rst(ARR) memset(ARR, 0, sizeof(ARR))
#define Mx(A, B) ((A)>(B)?(A):(B))
#define Mn(A, B) ((A)<(B)?(A):(B))
int g[MAXM];
int tot;
int n, m;
int pre[MAXM], invfac[MAXM];
ll pow_q(int a, int x) {
ll ret = 1;
for (ll t = a; x; x>>=1, t = t*t%MOD) {
if (x&1) ret = ret*t%MOD;
}
return ret;
}
ll inline inv(int a) {
return pow_q(a, MOD-2);
}
void init(){
pre[0] = 1;
rep(i, 1, m) pre[i] = (ll)pre[i-1]*(tot-i+1)%MOD;
invfac[0] = 1;
rep(i, 1, m) invfac[i] = (ll)invfac[i-1]*i%MOD;
invfac[m] = inv(invfac[m]);
for (int i = m-1; i; i--) invfac[i] = (ll)invfac[i+1]*(i+1)%MOD;
}
ll C(int m) {
return (ll)pre[m]*invfac[m]%MOD;
}
int main()
{
int T;scanf("%d", &T);
rep(ttttt, 1, T) {
scanf("%d%d", &n, &m);
tot = (pow_q(2, n)+MOD-1)%MOD;
init();
g[1] = g[2] = 0;
rep(i, 3, m) {
g[i] = (C(i-1) - g[i-1] - (ll)g[i-2]*(tot-i+2)%MOD)%MOD;
g[i] = (g[i]+MOD)%MOD;
g[i] = g[i]*inv(i)%MOD;
}
printf("%d\n", g[m]);
}
return 0;
}


（为什么是有序的而不是无序的？我也不知道：后面再说）

（任意选m-1个大部分不构成m-1个的合理方案，但是m个的可能方案能确定了）

f[m]=Am12n1f[m1]f[m2](2n1(m2))

2.化无序为有序，建立组合与排列的桥梁

g[m]=Cm12n1g[m1]g[m2](2n1(m2))i