//a^k % p intqmi(int a, int k, int p){ int res = 1; while (k) { if (k & 1) res = (longlong)res * a % p; k >>= 1;//最后一位抹去 a = (longlong)a * a % p; } return res; }
intmain(){ int m; scanf("%d", &m); while (m--) { int a, k, p; scanf("%d%d%d", &a, &k, &p); printf("%d\n", qmi(a, k, p)); } return0; }
//a^k % p intqmi(int a, int k, int p){ int res = 1; while (k) { if (k & 1) res = (longlong)res * a % p; k >>= 1;//最后一位抹去 a = (longlong)a * a % p; } return res; }
intmain(){ int m; scanf("%d", &m); while (m--) { int a, p; scanf("%d%d", &a, &p); int res = qmi(a, p - 2, p); if (a % p) printf("%d\n", res);//res != 0 表示a不是p的倍数 elseputs("impossible");//a是p的倍数 } return0; }