#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; long long inv(long long x, long long modc){ long long ans = 1, e = modc-2; x %= modc; while (e > 0){ if ((e & 1LL)) ans = (ans * x) % modc; e = e >> 1LL; x = (x*x) % modc; } return ans; } int main(){ long long N, P, X; cin >> N; while(N){ cin >> P; X = inv(P-1, P) * (P-1); if (P == 2) X = 2; cout << X << endl; N--; } return 0; }