#include int f[2][1100]; const int mod = 1000000007; int main() { int T; scanf("%d",&T); while(T--) { int n,p; scanf("%d%d",&n,&p); for(int i=0;i<=p;++i) f[0][i] = f[1][i] = 0; int cur = 0; f[cur][0] = 1; for(int i=0;imod)f[nxt][j] -= mod; f[nxt][(j+x) % p] += f[cur][j]; if(f[nxt][(j+x) % p]>mod)f[nxt][(j+x) % p] -= mod; } cur = 1-cur; } printf("%d\n",f[cur][0]); } return 0; }