#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
#define CRP(t, x) const t &x
#define OPL(t, x) bool operator<(CRP(t, x)) const
#define FIL(x, v) memset(x, v, sizeof(x))
#define CLR(x) FIL(x, 0)
#define NE1(x) FIL(x, -1)
#define INF(x) FIL(x, 0x3f)
typedef long long ll, i64;
const int N = 4e3;
bool notPrime[N];
int primes[N], pcnt;
int main()
{
    for (ll i = 2; i < N; i++)
        if (!notPrime[i])
            for (ll j = (primes[pcnt++] = i) * i; j < N; j += i)
                notPrime[j] = true;
    int T;
    long long n;
    scanf("%d", &T);
    while (T--)
    {
        scanf("%lld", &n);
        int ans = 63;
        for (int i = 0; i < pcnt; i++)
            if (n % primes[i] == 0)
            {
                int tmp = 0;
                for (; n % primes[i] == 0; n /= primes[i]) tmp++;
                ans = min(ans, tmp);
            }
        while (n > 1 && ans > 1)
        {
            bool flag = false;
            ll c = pow(n, 1.0 / 4);
            if (c * c * c * c == n) ans = min(ans, 4), flag = true;
            c++;
            if (c * c * c * c == n) ans = min(ans, 4), flag = true;
            if (flag) break;
            c = pow(n, 1.0 / 3);
            if (c * c * c == n) ans = min(ans, 3), flag = true;
            c++;
            if (c * c * c == n) ans = min(ans, 3), flag = true;
            if (flag) break;
            c = pow(n, 1.0 / 2);
            if (c * c == n) ans = min(ans, 2), flag = true;
            c++;
            if (c * c == n) ans = min(ans, 2), flag = true;
            if (flag) break;
            ans = 1;
            break;
        }
        printf("%d\n", ans);
    }
    return 0;
}
