# [TJOI2018]教科书般的亵渎

Description

Input

T ≤10 n ≤ 10^13 m ≤ 50

Output

Sample Input
2
10 1
5
4 2
1
2

Sample Output
415
135

MD……看题看半天系列

$k$一直是固定的，为$m+1$

/*program from Wolfycz*/
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x7f7f7f7f
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
inline char gc(){
static char buf[1000000],*p1=buf,*p2=buf;
}
template<typename T>inline T frd(T x){
int f=1; char ch=gc();
for (;ch<'0'||ch>'9';ch=gc())   if (ch=='-')    f=-1;
for (;ch>='0'&&ch<='9';ch=gc()) x=(x<<1)+(x<<3)+ch-'0';
return x*f;
}
int f=1;char ch=getchar();
for (;ch<'0'||ch>'9';ch=getchar())  if (ch=='-')    f=-1;
for (;ch>='0'&&ch<='9';ch=getchar())    x=(x<<1)+(x<<3)+ch-'0';
return x*f;
}
inline void print(int x){
if (x<0)    putchar('-'),x=-x;
if (x>9)    print(x/10);
putchar(x%10+'0');
}
template<typename T>inline T min(T x,T y){return x<y?x:y;}
template<typename T>inline T max(T x,T y){return x>y?x:y;}
const int N=50,p=1e9+7;
int prime[N+10],f[N+10],fac[N+10],inv[N+10];
bool inprime[N+10];
int mlt(int a,int b){
int res=1;
for (;b;b>>=1,a=1ll*a*a%p)  if (b&1)    res=1ll*res*a%p;
return res;
}
void prepare(int k){
int tot=0; f[1]=fac[0]=inv[0]=inv[1]=1,k++;
for (int i=2;i<=k;i++){
if (!inprime[i])    prime[++tot]=i,f[i]=mlt(i,k-1);
for (int j=1;j<=tot&&i*prime[j]<=k;j++){
inprime[i*prime[j]]=1;
f[i*prime[j]]=1ll*f[i]*f[prime[j]]%p;
if (i%prime[j]==0)  break;
}
}
for (int i=1;i<=k;i++)  f[i]=(f[i]+f[i-1])%p;

for (int i=1;i<=k;i++)  fac[i]=1ll*fac[i-1]*i%p;
for (int i=2;i<=k;i++)  inv[i]=1ll*(p-p/i)*inv[p%i]%p;
for (int i=1;i<=k;i++)  inv[i]=1ll*inv[i-1]*inv[i]%p;
}
int calc(int k,ll n){
static int Pre[N+10],Suf[N+10];
n%=p,k++,Pre[0]=n,Suf[k]=n-k; int res=0;
for (int i=1;i<=k;i++)  Pre[i]=1ll*Pre[i-1]*(n-i)%p;
for (int i=k-1;~i;i--)  Suf[i]=1ll*Suf[i+1]*(n-i)%p;
for (int i=0;i<=k;i++){
int tmp=1ll*f[i]*inv[i]%p*inv[k-i]%p;
if (i!=0)   tmp=1ll*tmp*Pre[i-1]%p;
if (i!=k)   tmp=1ll*tmp*Suf[i+1]%p;
res=(res+((k-i)&1?-1:1)*tmp)%p;
}
return (res+p)%p;
}
int main(){
static ll A[N+10];
}