#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxr = 1e6 + 6, maxn = 1e6 + 6;
const ll mod = 1e9 + 7;
bool notPrime[maxn];
ll ch[maxr + 50][25];
vector<ll> primes;
vector<int> l[maxn];
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
ch[0][0] = 1;
for(int i = 1; i <= 1e6 + 22; i++) {
ch[i][0] = 1;
for(int j = 1; j <= 20; j++) {
ch[i][j] = (ch[i - 1][j - 1] + ch[i - 1][j]) % mod;
}
}
for(int i = 2; i <= 1e6; i++) {
if(!notPrime[i]) {
primes.push_back(i);
l[i].push_back(1);
for(int j = i + i; j <= 1e6; j += i) {
notPrime[j] = true;
l[j].push_back(1);
for(int k = j/i; k % i == 0; k /= i) {
l[j].back()++;
}
}
}
}
int q;
scanf("%d", &q);
while(q--) {
int r, n;
scanf("%d%d", &r, &n);
ll ans = 0;
if(r == 0) {
printf("%d\n", 1 << l[n].size());
}
else {
vector<int> divs;
divs.push_back(1);
int N = n;
for(int p : primes) {
if(n == 1 || p*p > n) {
break;
}
int lst = 0;
while(n % p == 0) {
int end = divs.size();
for(int i = lst; i < end; i++) {
divs.push_back(p*divs[i]);
}
lst = end;
n /= p;
}
}
if(n != 1) {
int end = divs.size();
for(int i = 0; i < end; i++) {
divs.push_back(n*divs[i]);
}
}
for(int d : divs) {
ll coeff = 1;
for(int x : l[d]) {
coeff = (coeff * ch[r + x - 1][x]) % mod;
}
ans = (ans + coeff*(1 << l[N/d].size())) % mod;
}
printf("%lld\n", ans);
}
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnR5cGVkZWYgbG9uZyBsb25nIGxsOwoKY29uc3QgaW50IG1heHIgPSAxZTYgKyA2LCBtYXhuID0gMWU2ICsgNjsKY29uc3QgbGwgbW9kID0gMWU5ICsgNzsKCmJvb2wgbm90UHJpbWVbbWF4bl07CmxsIGNoW21heHIgKyA1MF1bMjVdO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