#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 1000010;
int prime[5005];
long long f[MAXN][22];
void getPrime() {
  for (int i = 2; i <= 5000; i++) {
    if (!prime[i]) prime[++prime[0]] = i;
    for (int j = 1; j <= prime[0] && prime[j] <= 5000 / i; j++) {
      prime[prime[j] * i] = 1;
      if (i % prime[j] == 0) break;
    }
  }
}
void init() {
  f[0][0] = 1;
  for (int i = 1; i <= 20; ++i) {
    f[0][i] = 2;
  }
  for (int i = 1; i <= 1000000; ++i) {
    f[i][0] = 1;
    for (int j = 1; j <= 20; ++j) {
      f[i][j] = (f[i][j - 1] + f[i - 1][j]) % MOD;
    }
  }
}
int q, r, n;
int main() {
  init();
  getPrime();
  scanf("%d", &q);
  while (q--) {
    scanf("%d%d", &r, &n);
    long long ans = 1;
    int cnt = 0;
    for (int i = 1, tmp; prime[i] * prime[i] <= n && i <= prime[0]; ++i) {
      tmp = prime[i];
      if (n == 1) break;
      if (n % tmp == 0) {
        while (n % tmp == 0) {
          n /= tmp;
          cnt++;
        }
      }
      ans = ans * f[r][cnt] % MOD;
      cnt = 0;
    }
    if (n > 1) {
      ans = ans * (long long)f[r][1] % MOD;
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
