#include<bits/stdc++.h>
using namespace std;

using ll = long long;

const int N = 5e5;

int n, spf[N+1], f[N+1];

void precompute() {
    for (int i = 2; i <= N; i++)
        if (spf[i] == 0)
            for (int j = i; j <= N; j += i)
                if (spf[j] == 0) spf[j] = i;
    f[1] = 1;
    for (int i = 2; i <= N; i++)
        f[i] = f[i / spf[i]] + 1;
}

void solve() {
    cin >> n;
    int k = 0;
    for (int i = 1; i <= n; i++)
        k = max(k, f[i]);
    cout << k << '\n';
    for (int i = 1; i <= n; i++)
        cout << f[i] << ' ';
    cout << '\n';
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);

    precompute();

    int tests = 1; cin >> tests;
    while (tests--) solve();

    #ifndef ONLINE_JUDGE
    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif

    return 0;
}
