#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 7;
const int mod = 1e9 + 7;
void upd(int& x, int y) {
  x += y;
  if (x >= mod) x -= mod;
}
int qpow(int a, int b) {
  int aa = a, res = 1;
  for (; b; b >>= 1) {
    if (b & 1) res = 1ll * res * aa % mod;
    aa = 1ll * aa * aa % mod;
  }
  return res;
}
int bin[N], pin[N];
void init() {
  bin[0] = pin[0] = 1;
  for (int i = 1; i <= N - 1; i++) bin[i] = 1ll * bin[i - 1] * i % mod;
  pin[N - 1] = qpow(bin[N - 1], mod - 2);
  for (int i = N - 2; i >= 1; i--) pin[i] = 1ll * pin[i + 1] * (i + 1) % mod;
}
int C(int x, int y) { return 1ll * bin[x] * pin[x - y] % mod * pin[y] % mod; }
int n, p[N], top = 0, Q, lc[N], lv[N], vis[N];
void init2() {
  int lim = N - 1;
  for (int i = 2; i <= lim; i++) {
    if (!vis[i]) {
      p[++top] = i;
      lv[i] = i;
      lc[i] = 1;
    }
    for (int k = 1; k <= top; k++) {
      if (1ll * i * p[k] > lim) break;
      vis[i * p[k]] = 1;
      if (i % p[k]) {
        lv[i * p[k]] = p[k];
        lc[i * p[k]] = 1;
      } else {
        lv[i * p[k]] = lv[i] * p[k];
        lc[i * p[k]] = lc[i] + 1;
        break;
      }
    }
  }
}
int f(int k, int r) {
  return (1ll * 2 * C(r + k - 1, r) + 1ll * C(r + k - 1, r - 1)) % mod;
}
int main() {
  init();
  init2();
  scanf("%d", &Q);
  int n, r;
  while (Q--) {
    scanf("%d%d", &r, &n);
    int ans = 1;
    while (n != 1) {
      ans = 1ll * ans * f(lc[n], r) % mod;
      n /= lv[n];
    }
    printf("%d\n", ans);
  }
}
