#include #include #include #include #include using namespace std; typedef long long LL; LL Mul(LL a,LL b,LL p){ LL ans=0; for(;b;b>>=1,a=(a<<1)%p) if(b&1) (ans+=a)%=p; return ans; } int main(){ int T; cin>>T; while(T--){ LL q,p; cin>>q>>p; if(q&1) cout<>1,q-2,p)<>1,q-1,p)<