Pagini recente » Cod sursa (job #3152970) | Cod sursa (job #2975388) | Cod sursa (job #155903) | Cod sursa (job #625601) | Cod sursa (job #635571)
Cod sursa(job #635571)
#include <stdio.h>
#define MOD 10007
int FastPow (int A, int B)
{
if (B == 0)
return 1;
int now = FastPow (A, B >> 1);
if (B & 1)
return ((long long)now * now * A) % MOD;
else
return (long long)now * now % MOD;
}
int main ()
{
int N, M, K, P, T, sol;
freopen ("matrice5.in", "r", stdin);
freopen ("matrice5.out", "w", stdout);
scanf ("%d", &T);
while (T --)
{
scanf ("%d%d%d%d", &N, &M, &P, &K);
sol = ((long long)FastPow (P, N * M) * FastPow (K, (N - 1) * (M - 1))) % MOD;
printf ("%d\n", sol);
}
return 0;
}