#include using namespace std; typedef long long ll; ll mod_inv(ll a,ll p){ ll b=p,x=1LL,y=0LL; while(b){ ll t=a/b; a-=t*b; swap(a,b); x-=t*y; swap(x,y); } return (x%p+p)%p; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; while(n--){ ll p; cin >> p; if(p!=2)printf("%lld\n",mod_inv(p-1,p)*(p-1)); else printf("2\n"); } }