#include <bits/stdc++.h>
using namespace std;
pair<int, int> PII;
const int N = 1000010;
const int P = 1e9 + 7;
int c[100][100], n, r, f[N], cnt, prime[N], tot;
bool pd[N];
int g[N][22];
int Next[N * 5], in[N];
int h[N * 5];
inline void add(int &x, int y) { x = (x + y) % P; }
int main() {
  c[0][0] = 1;
  for (int i = 1; i < 100; i++) {
    c[i][0] = 1;
    for (int j = 1; j <= i; j++) c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % P;
  }
  f[1] = 1;
  int t;
  int cnt2;
  for (int i = 2; i < N; i++) {
    if (!pd[i]) {
      prime[cnt++] = i;
      f[i] = 1;
    }
    for (int j = 0; j < cnt && i * prime[j] < N; j++) {
      pd[i * prime[j]] = true;
      t = i;
      while (t % prime[j] == 0) t /= prime[j], cnt2++;
      f[i * prime[j]] = f[t] + 1;
      if (i % prime[j] == 0) break;
    }
  }
  for (int i = 0; i < cnt; i++) {
    for (int j = prime[i]; j < N; j += prime[i]) {
      t = j, cnt2 = 0;
      while (t % prime[i] == 0) t /= prime[i], cnt2++;
      ++tot;
      Next[tot] = in[j];
      h[tot] = cnt2;
      in[j] = tot;
    }
  }
  for (int i = 1; i <= 20; i++) g[0][i] = 2;
  for (int i = 1; i < N; i++) {
    g[i][0] = 1;
    for (int j = 1; j <= 20; j++) {
      add(g[i][j], g[i][j - 1]);
      add(g[i][j], g[i - 1][j]);
    }
  }
  int q, r, n, ans;
  scanf("%d", &q);
  while (q--) {
    scanf("%d%d", &r, &n);
    ans = 1;
    for (int i = in[n]; i != 0; i = Next[i]) {
      ans = 1ll * ans * g[r][h[i]] % P;
    }
    printf("%d\n", ans);
  }
  return 0;
}
