#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int s = 0, t = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') t = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
  return s * t;
}
const int P = 1e9 + 7;
const int N = 2e6 + 5;
bool vis[N];
int tot, a[30], b[30];
int fac[N], inv[N], p[N / 10], lp[N];
int ksm(int x, int k) {
  int res = 1;
  while (k) {
    if (k & 1) res = 1ll * res * x % P;
    x = 1ll * x * x % P, k >>= 1;
  }
  return res;
}
void Pre(int n) {
  fac[0] = 1;
  for (int i = 1; i <= n; i++) fac[i] = 1ll * fac[i - 1] * i % P;
  inv[n] = ksm(fac[n], P - 2);
  for (int i = n; i >= 1; i--) inv[i - 1] = 1ll * inv[i] * i % P;
  for (int i = 2; i <= n; i++) {
    if (!vis[i]) p[++tot] = i, lp[i] = i;
    for (int j = 1; j <= tot && i * p[j] <= n; j++) {
      vis[i * p[j]] = 1, lp[i * p[j]] = p[j];
      if (i % p[j] == 0) break;
    }
  }
}
int C(int n, int m) {
  return (n < m || m < 0) ? 0 : 1ll * fac[n] * inv[m] % P * inv[n - m] % P;
}
int Solve(int r, int n) {
  a[tot = 0] = 0;
  while (n ^ 1) {
    int t = lp[n];
    n /= t;
    if (t ^ a[tot])
      a[++tot] = t, b[tot] = 1;
    else
      b[tot]++;
  }
  if (r == 0) return ksm(2, tot);
  int res = 1;
  for (int i = 1; i <= tot; i++) {
    int l = b[i], tmp = C(r + l - 1, r - 1);
    for (int j = 1; j <= l; j++)
      tmp = (tmp + 2ll * C(r + l - j - 1, r - 1) % P) % P;
    res = 1ll * res * tmp % P;
  }
  return res;
}
int main() {
  Pre(2e6);
  for (int T = read(); T; T--) {
    int r = read(), n = read();
    printf("%d\n", Solve(r, n));
  }
  return 0;
}
