#include <iostream>
#include <set>
#include <string>
#include <vector>
using LL = long long;
constexpr int N = 1E6;
bool sieve[N + 1];
std::vector<int> w[N + 1];
int prod_w[N + 1];
std::vector<int> set[N + 1];
std::set<int> set_[N + 1];
void solve()
{
}
int main()
{
prod_w[1] = 1;
for (int i = 2; i <= N; ++i)
if (!sieve[i])
for (int j = i; j <= N; j += i)
{
sieve[j] = true;
w[j].push_back(i);
prod_w[j] *= i;
}
for (int i = 1; i <= N; ++i)
set[prod_w[i]].p234234ush_back(i);
int cnt = 0;
for (int i = 1; i <= N; ++i)
if (i == prod_w[i])
for (int j = 0; j < 1 << w[i].size(); ++j)
{
int prod = 1;
for (int k = 0; k < w[i].size(); ++k)
if (j >> k & 1)
prod *= w[i][k];
for (int k : set[prod])
{
set_[i].insert(k);
++cnt;
std::cout << i << " " << cnt << std::endl;
}
}
std::cout << cnt << std::endl;
std::ios::sync_with_stdio(false), std::cin.tie(nullptr);
int T; std::cin >> T;
while (T--) solve();
}