#line 1 "a.cpp" #include using namespace std; #line 1 "/home/kotatsugame/library/math/extgcd.cpp" template T extgcd(T a,T b,T&x,T&y) { if(b==0) { x=1; y=0; return a; } T q=a/b; T g=extgcd(b,a-q*b,y,x); y-=q*x; return g; } #line 4 "a.cpp" int T; main() { cin>>T; for(;T--;) { long X,K;cin>>X>>K; long x,y; long m=1e9+6; extgcd(m,K,x,y); y%=m; if(y>=1; X=X*X%m; } cout<