#include <bits/stdc++.h>
#pragma comment(linker, "/stack:16777216")
using namespace std;
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const long long LINF = INF * (long long)INF;
const int MOD = 1000 * 1000 * 1000 + 7;
const int MAX = 1000007;
int dil[MAX];
int p2[2 * MAX];
int f[2 * MAX];
int of[2 * MAX];
int n;
int mpow(long long num, int step) {
  long long res = 1;
  while (step) {
    if (step & 1) {
      res = (res * num) % MOD;
    }
    num = (num * num) % MOD;
    step /= 2;
  }
  return (int)res;
}
int q[50];
int nq;
long long ans;
int d, a;
long long WTF[30];
int main() {
  f[0] = of[0] = p2[0] = 1;
  for (int i = (1); i < (2 * MAX); i++) {
    p2[i] = (p2[i - 1] * 2LL) % MOD;
    f[i] = (1LL * f[i - 1] * i) % MOD;
    of[i] = mpow(f[i], MOD - 2);
  }
  for (int i = (2); i < (MAX); i++) {
    if (!dil[i]) {
      for (int j = i; j < MAX; j += i) dil[j] = i;
    }
  }
  scanf("%d", &n);
  for (int i = (0); i < (n); i++) {
    scanf("%d%d", &d, &a);
    {
      nq = 0;
      long long ans = 1;
      int prev = 0, ct = 0, s = 0;
      while (a != 1) {
        s++;
        if (ct && dil[a] != prev) {
          q[nq++] = ct;
          ct = 0;
        }
        prev = dil[a];
        a /= dil[a];
        ct++;
      }
      if (ct != 0) q[nq++] = ct;
      WTF[0] = f[d - 1];
      for (int i = (1); i < (21); i++) {
        WTF[i] = WTF[i - 1];
        WTF[i] = (WTF[i] + 1LL * f[d + i - 1] * of[i]) % MOD;
      }
      if (!d)
        printf("%d\n", p2[nq]);
      else {
        for (int i = (0); i < (nq); i++) {
          long long add = 2 * WTF[q[i]];
          add = (add - 1LL * f[d + q[i] - 1] * of[q[i]] % MOD + MOD) % MOD;
          ans = ans * add % MOD * of[d - 1] % MOD;
        }
        printf("%I64d\n", ans);
      }
    }
  }
}
