#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, N = 1e6 + 5, LN = 25;
inline int scan() {
  int res = 0;
  char c = getchar();
  while (c < '0' or c > '9') c = getchar();
  while (c >= '0' and c <= '9') {
    res = (res << 1) + (res << 3) + (c - '0');
    c = getchar();
  }
  return res;
}
inline int add(int a, int b) {
  int res = a + b;
  if (res >= mod) res -= mod;
  return res;
}
inline int mult(int a, int b) {
  long long res = a * 1LL * b;
  return res % mod;
}
int big[N];
void pre() {
  for (int i = 0; i < N; i++) big[i] = i;
  for (int i = 2; i < N; i++) {
    if (big[i] != i) continue;
    for (int j = i; j < N; j += i) {
      big[j] = i;
    }
  }
}
int q;
int dp[N][LN];
int sum[N][LN];
int main() {
  dp[0][0] = 1;
  sum[0][0] = 1;
  pre();
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < LN; j++) {
      if (i == 0 and j == 0) continue;
      dp[i][j] = i != 0 ? sum[i - 1][j] : 2;
      sum[i][j] = add(j != 0 ? sum[i][j - 1] : 0, dp[i][j]);
    }
  }
  q = scan();
  while (q--) {
    int r = scan(), n = scan();
    int ans = 1;
    while (n != 1) {
      int cnt = 0;
      int which = big[n];
      while (n % which == 0) {
        n /= which;
        cnt++;
      }
      ans = mult(ans, dp[r][cnt]);
    }
    printf("%d\n", ans);
  }
}
