Pagini recente » Cod sursa (job #978077) | Cod sursa (job #418768) | Cod sursa (job #750933) | Cod sursa (job #1421503) | Cod sursa (job #2947543)
#include <fstream>
const int MOD=10007;
#define int long long int
using namespace std;
ifstream fin("matrice5.in");
ofstream fout("matrice5.out");
void test();
long long pt(int a, int b)
{
long long p=1;
while(b)
{
if(b%2==1) p=(p*a)%MOD;
a=(a*a)%MOD;
b/=2;
}
return p;
}
signed main()
{
ios_base::sync_with_stdio(false);
fin.tie(0);
int t; fin>>t;
while(t--) test();
}
void test()
{
long long x, n, m, p, k, y;
fin>>n>>m>>p>>k;
x=pt(k*p, (n-1)*(m-1));
y=pt(p, m+n-1);
fout<<(x*y)%MOD<<'\n';
}