#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000005;
const int MOD = 1000000007;
int pr[MAXN], dp[MAXN][20], f[MAXN], v[MAXN], p;
int count(int a) {
  int ans = 0;
  for (int prev = 0; a != 1; a /= pr[a]) {
    if (pr[a] != prev) prev = pr[a], ans++;
  }
  return ans;
}
void fun(int a) {
  p = 0;
  while (a != 1) {
    int c = 0, cur = pr[a];
    while (pr[a] == cur) a /= pr[a], c++;
    v[p++] = c;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int q;
  cin >> q;
  for (int i = 2; i < MAXN; i++) {
    if (pr[i] == 0) {
      for (int j = i; j < MAXN; j += i)
        if (pr[j] == 0) pr[j] = i;
    }
  }
  dp[0][0] = 1;
  for (int i = 1; i < 20; i++) dp[0][i] = 2;
  for (int i = 1; i < MAXN; i++) {
    int prev = 0;
    for (int j = 0; j < 20; j++) {
      prev += dp[i - 1][j];
      prev %= MOD;
      dp[i][j] = prev;
    }
  }
  for (int i = 1; i < MAXN; i++) {
    int k = count(i);
    f[i] = (1 << k);
  }
  while (q--) {
    int r, n;
    cin >> r >> n;
    if (r == 0) {
      cout << f[n] << '\n';
      continue;
    }
    fun(n);
    long long ans = 1;
    for (int i = 0; i < p; i++) ans = ans * dp[r][v[i]] % MOD;
    cout << ans << '\n';
  }
  return 0;
}
