//MJRT #include #include #include #include ////////////////////// #include #include #include #include #include #include #include /////////////////////// #include #include #include #include #include #include #include /////////////////////// //#include //pd_bs库,hdu&&poj不支持 using namespace std; #define lowbit(x) ((x)&(-x)) static int INDEX = 0,BUGs = 0; template inline void gmax(T1 &a, T2 b) { if (b>a)a = b; } template inline void gmin(T1 &a, T2 b) { if (b T MAX(T a, T b) { return a > b ? a : b; } template T MIN(T a, T b) { return a < b ? a : b; } template T GCD(T a, T b) { return b ? GCD(b, a%b) : a; } template T LCM(T a, T b) { return a / GCD(a,b) * b; } #define BUG() cout << "There is BUG No." << BUGs++ <>= 1; a = (a + a) % mod; } return ans; } int main() { //ios::sync_with_stdio(false); #ifndef ONLINE_JUDGE //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); #endif int Case; scanf("%d",&Case); while(Case--) { scanf("%I64d%I64d",&q,&p); printf("%I64d\n",multi((q-1)/2,q-2,p)); } return 0; }