Pagini recente » Cod sursa (job #72194) | Cod sursa (job #475500) | Cod sursa (job #2307902) | Cod sursa (job #297293) | Cod sursa (job #640446)
Cod sursa(job #640446)
# include <fstream>
# include <iostream>
# define P 10007
using namespace std;
int pow (int b, int e)
{
if (e==1)
return b;
if (e%2)
return (b*pow(b, e-1))%P;
int r=pow(b, e/2);
return (r*r)%P;
}
int main ()
{
ifstream fin ("matrice5.in");
freopen("matrice5.out", "w", stdout);
int t, n, m, p, k;
fin>>t;
for(;t--;)
{
fin>>n>>m>>p>>k;
printf ("%d\n", (pow(p*k,(n-1)*(m-1))*pow(p, n+m-1))%P);
}
return 0;
}