Pagini recente » Cod sursa (job #2857840) | Cod sursa (job #118551) | Cod sursa (job #2299933) | Diferente pentru problema/soc2 intre reviziile 10 si 8 | Cod sursa (job #3304981)
#include <bits/stdc++.h>
using namespace std;
const int mod=1e4+7;
int lgpow(int a, int b){
int res=1;
while (b){
if (b&1){
res=res*a%mod;
}
a=a*a%mod;
b>>=1;
}
return res;
}
int main()
{
freopen("matrice5.in", "r", stdin);
freopen("matrice5.out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;cin>>t;
while (t--){
int n,m,p,k;cin>>n>>m>>p>>k;
int ans=lgpow((p*k)%mod, ((n-1)*(m-1))%(mod-1))%mod*lgpow(p, (n+m-1)%(mod-1))%mod;
cout<<ans<<'\n';
}
return 0;
}