#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++) using namespace std; typedef long long int ll; typedef vector VI; typedef pair PI; const double EPS=1e-9; const ll mod = 1e9+7; PI conv(const string &s) { ll a = 0; int over = 0; REP(i, 0, s.size()) { a *= 10; a += s[i] - '0'; if (a >= mod) { over = 1; } a %= mod; } return PI((int)a, over); } int main(void){ int t; cin >> t; REP(i, 0, t) { string c, p; cin >> c >> p; PI cc = conv(c), pc = conv(p); if (pc.second) { cout << 0 << endl; continue; } ll cq = cc.first, pq = pc.first; ll sum = 1; cq += mod - pq + 1; cq %= mod; REP(j, 0, pq) { sum *= (cq - j + mod); sum %= mod; } cout << sum << endl; } }