#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int pri[1000000 + 5];
int b[1000000 + 5];
void getPrime() {
  for (int i = 2; i <= 1000000; i++) {
    if (pri[i] == 0) {
      pri[++pri[0]] = i;
      b[i] = i;
    }
    for (int j = 1; j <= pri[0] && pri[j] <= 1000000 / i; j++) {
      pri[pri[j] * i] = 1;
      b[pri[j] * i] = pri[j];
      if (i % pri[j] == 0) break;
    }
  }
}
int dp[1000005][21];
int q, r, n;
int main() {
  dp[0][0] = 1;
  for (int j = 1; j <= 20; j++) {
    dp[0][j] = 2;
  }
  for (int i = 1; i <= 1000000; i++) {
    int tmp = 0;
    for (int j = 0; j <= 20; j++) {
      tmp = (tmp + dp[i - 1][j]) % mod;
      dp[i][j] = tmp;
    }
  }
  getPrime();
  scanf("%d", &q);
  while (q--) {
    scanf("%d%d", &r, &n);
    long long tmp = 1;
    int x = n;
    while (x > 1) {
      int p = b[x];
      int cnt = 0;
      while (b[x] == p) {
        x /= p;
        cnt++;
      }
      tmp = tmp * dp[r][cnt] % mod;
    }
    printf("%I64d\n", tmp);
  }
  return 0;
}
