#include <bits/stdc++.h>
using namespace std;
long long modx(long long Base, long long exponent) {
  long long ans = 1;
  if (Base == 1) return Base;
  while (exponent) {
    if (exponent & 1) ans = (ans * Base) % 1000000007;
    Base = (Base * Base) % 1000000007;
    exponent = exponent >> 1;
  }
  return ans;
}
long long inmodx(long long num) { return (modx(num, 1000000007 - 2LL)); }
struct node {
  node() {}
};
bool cmp() { return false; }
const int N = 1000009;
vector<int> p;
bool isp[N];
int sz_p;
vector<int> fact[N];
void sieve() {
  int i, j, cnt, x;
  isp[0] = isp[1] = 1;
  for (i = (2); i < (1005); i++) {
    if (!isp[i]) {
      for (j = i + i; j < N; j += i) isp[j] = 1;
    }
  }
  p.push_back(2);
  for (i = 3; i < N; i += 2) {
    if (!isp[i]) p.push_back(i);
  }
  sz_p = (int)((p).size());
  for (i = (0); i < (sz_p); i++) {
    for (j = p[i]; j < N; j += p[i]) {
      cnt = 0;
      x = j;
      while (x % p[i] == 0) {
        x /= p[i];
        cnt++;
      }
      fact[j].push_back(cnt);
    }
  }
}
long long factor[N + 50], ifact[N + 50];
void factorial() {
  int i;
  factor[0] = ifact[0] = 1LL;
  for (i = (1); i < (N + 50); i++) {
    factor[i] = (factor[i - 1] * ((long long)(i))) % 1000000007;
    ifact[i] = inmodx(factor[i]);
  }
}
long long comb(int n, int r) {
  if (n < 0 || r < 0 || r > n) return 0LL;
  long long ans = (factor[n] * ifact[r]) % 1000000007;
  ans = (ans * ifact[n - r]) % 1000000007;
  return ans;
}
int main() {
  sieve();
  factorial();
  int t, n, r, i, j, y;
  long long ans, sum;
  scanf("%d", &(t));
  while (t--) {
    scanf("%d", &(r));
    scanf("%d", &(n));
    ans = 1LL;
    if (r == 0)
      ans = modx(2LL, (long long)(int)((fact[n]).size()));
    else {
      for (i = (0); i < ((int)((fact[n]).size())); i++) {
        y = fact[n][i];
        sum = (comb(y + r, r) + comb(y + r - 1, r));
        if (sum >= 1000000007) sum -= 1000000007;
        ans = (ans * sum) % 1000000007;
      }
    }
    printf("%lld\n", (ans));
  }
  return 0;
}
