#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1500000;
bool isp[MAXN];
int fac[MAXN], invfac[MAXN], primes[MAXN];
const int MOD = 1000000007;
void mult(int &a, long long b) {
  a = (a * b) % MOD;
  if (a < 0) a += MOD;
}
int modex(int a, int p) {
  if (!p) return 1;
  if (p & 1) return ((long long)a * modex(a, p - 1)) % MOD;
  long long v = modex(a, p >> 1);
  return (v * v) % MOD;
}
int choose(int a, int b) {
  if (b > a) return 0;
  int ret = fac[a];
  mult(ret, invfac[b]);
  mult(ret, invfac[a - b]);
  return ret;
}
int main() {
  int nn = 0;
  memset(isp, 1, sizeof(isp));
  for (int i = 2; i < MAXN; ++i)
    if (isp[i]) {
      primes[nn++] = i;
      for (int j = i + i; j < MAXN; j += i) isp[j] = false;
    }
  fac[0] = invfac[0] = 1;
  for (int i = 1; i < MAXN; ++i) {
    fac[i] = fac[i - 1];
    mult(fac[i], i);
    invfac[i] = modex(fac[i], MOD - 2);
  }
  int Q;
  scanf("%d", &Q);
  while (Q--) {
    int r, n;
    scanf("%d%d", &r, &n);
    int i = 0;
    int ans = 1;
    while (primes[i] * primes[i] <= n) {
      int p = primes[i];
      if (n % p == 0) {
        int d = 0;
        while (n % p == 0) {
          ++d;
          n /= p;
        }
        mult(ans, 2 * choose(d + r, d) - choose(d + r - 1, d));
      }
      ++i;
    }
    if (n > 1) mult(ans, 2 * choose(1 + r, 1) - choose(r, 1));
    printf("%d\n", ans);
  }
}
