#include <bits/stdc++.h>
using namespace std;
template <typename T>
void _R(T &x) {
  cin >> x;
}
void _R(int &x) { scanf("%d", &x); }
void _R(long long &x) { scanf("%" PRId64, &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template <typename T, typename... U>
void R(T &head, U &...tail) {
  _R(head);
  R(tail...);
}
template <typename T>
void _W(const T &x) {
  cout << x;
}
void _W(const int &x) { printf("%d", x); }
template <typename T>
void _W(const vector<T> &x) {
  for (auto i = x.cbegin(); i != x.cend(); i++) {
    if (i != x.cbegin()) putchar(' ');
    _W(*i);
  }
}
void W() {}
template <typename T, typename... U>
void W(const T &head, const U &...tail) {
  _W(head);
  putchar(sizeof...(tail) ? ' ' : '\n');
  W(tail...);
}
const int N = 2e6 + 10;
const long long MOD = 1e9 + 7;
vector<int> primes;
int p_tbl[N];
void sieve() {
  p_tbl[1] = 1;
  for (int i = 2; i < N; i++) {
    if (!p_tbl[i]) {
      primes.push_back(i);
      p_tbl[i] = i;
    }
    for (int p : primes) {
      int x = i * p;
      if (x >= N) break;
      p_tbl[x] = p;
      if (i % p == 0) break;
    }
  }
}
long long inv[N], fac[N], ifac[N];
void predo() {
  inv[1] = 1;
  for (int i = (2); i <= int(N - 1); i++)
    inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
  fac[0] = 1;
  for (int i = (1); i <= int(N - 1); i++) fac[i] = fac[i - 1] * i % MOD;
  ifac[0] = 1;
  for (int i = (1); i <= int(N - 1); i++) ifac[i] = ifac[i - 1] * inv[i] % MOD;
}
long long C(int n, int m) { return fac[n] * ifac[m] % MOD * ifac[n - m] % MOD; }
long long F(int n, int m) { return C(n + m, n); }
int main() {
  sieve();
  predo();
  int q;
  R(q);
  while (q--) {
    int r, n;
    R(r, n);
    long long ans = 1;
    while (n > 1) {
      int p = p_tbl[n];
      int e = 1;
      n /= p;
      while (n % p == 0) {
        e++;
        n /= p;
      }
      long long now = 0;
      now += F(r, e - 1);
      now += F(r, e);
      ans = (ans * now) % MOD;
    }
    W(ans);
  }
  return 0;
}
