#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int N = 1000002;
const int R = 1000002;
const int A = 22;
int binom[R + A][A];
int sieve[N];
int firstRev[R + A + 1];
void fix(int &x) {
  if (x >= MOD) x -= MOD;
}
void firstModRev(int n) {
  firstRev[1] = 1;
  for (int i = (2); i <= (n); ++i) {
    firstRev[i] = (-(long long)(MOD / i) * firstRev[MOD % i]) % MOD;
    if (firstRev[i] < 0) firstRev[i] += MOD;
  }
}
void pre() {
  for (int i = (0); i <= (R + A - 1); ++i) {
    binom[i][0] = 1;
  }
  for (int i = (1); i <= (R + A - 1); ++i)
    for (int j = (1); j <= (A - 1); ++j) {
      binom[i][j] = binom[i - 1][j] + binom[i - 1][j - 1];
      fix(binom[i][j]);
    }
  for (int i = (1); i <= (R + A - 1); ++i)
    for (int j = (1); j <= (A - 1); ++j) {
      binom[i][j] += binom[i - 1][j - 1];
      fix(binom[i][j]);
    }
  for (int i = (2); i <= (N - 1); ++i) sieve[i] = i;
  for (int i = (2); i <= (N - 1); ++i)
    if (sieve[i] == i) {
      for (int j = 2 * i; j < N; j += i) {
        sieve[j] = min(sieve[j], i);
      }
    }
  firstModRev(R + A);
}
long long expo(long long a, long long n, long long mod) {
  long long ans = 1;
  while (n) {
    if (n & 1LL) ans = (ans * a) % mod;
    n >>= 1;
    a = (a * a) % mod;
  }
  return ans;
}
long long revMod(int a) {
  if (a <= R + A) {
    return firstRev[a];
  }
  return expo(a, MOD - 2, MOD);
}
int bigCnt[N];
void cleanUp(vector<int> &primes) {
  for (int p : primes) bigCnt[p] = 0;
}
vector<int> factor(int n) {
  vector<int> ps;
  while (n > 1) {
    int p = sieve[n];
    ps.push_back(p);
    while (n % p == 0) {
      bigCnt[p]++;
      n /= p;
    }
  }
  return ps;
}
int solve(int r, int n) {
  auto primes = factor(n);
  int ps = primes.size();
  if (r == 0) {
    cleanUp(primes);
    return (1 << ps);
  }
  vector<int> aval(ps), bval(ps);
  for (int i = (0); i <= (ps - 1); ++i) {
    int alpha = bigCnt[primes[i]];
    aval[i] = binom[alpha + r - 1][alpha];
    bval[i] = binom[alpha + r - 2][alpha - 1];
  }
  long long ans = 1;
  for (long long a : aval) {
    ans = (ans * a) % MOD;
  }
  for (int i = (0); i <= (ps - 1); ++i) {
    long long ratio = bval[i] * revMod(aval[i]);
    ratio = (ratio + 1) % MOD;
    ans = (ans * ratio) % MOD;
  }
  cleanUp(primes);
  return ans;
}
int main() {
  pre();
  int q;
  scanf("%d", &q);
  while (q--) {
    int r, n;
    scanf("%d %d", &r, &n);
    cout << solve(r, n) << '\n';
  }
  return 0;
}
