Pagini recente » Cod sursa (job #186647) | Cod sursa (job #2981820) | Cod sursa (job #190504) | Cod sursa (job #2376889) | Cod sursa (job #2948775)
#include <bits/stdc++.h>
//#pragma GCC optimize ("03")
#define FastIO ios_base::sync_with_stdio(false) , cin.tie(0) , cout.tie(0)
#define FILES freopen("matrice5.in" , "r" , stdin) , freopen("matrice5.out" , "w" , stdout)
#define ll long long
#define ull unsigned long long
#define ld long double
#define eb emplace_back
#define pb push_back
#define qwerty1 first
#define qwerty2 second
#define qwerty3 -> first
#define qwerty4 -> second
#define umap unordered_map
#define uset unordered_set
#define pii pair < ll , ll >
#define pq priority_queue
#define dbg(x) cerr << #x << ": " << x << '\n'
namespace FastRead
{
char __buff[5000];ll __lg = 0 , __p = 0;
char nc()
{
if(__lg == __p){__lg = fread(__buff , 1 , 5000 , stdin);__p = 0;if(!__lg) return EOF;}
return __buff[__p++];
}
template<class T>void read(T&__x)
{
T __sgn = 1; char __c;while(!isdigit(__c = nc()))if(__c == '-')__sgn = -1;
__x = __c - '0';while(isdigit(__c = nc()))__x = __x * 10 + __c - '0';__x *= __sgn;
}
}
using namespace FastRead;
using namespace std;
const ll N = 2.5e5 + 10;
const ll M = 10007;
ll n , m , k , p;
ll pw(ll n , ll p)
{
ll ans = 1;
for( ; p ; p >>= 1 , n = n * n % M)
if(p & 1)
ans = ans * n % M;
return ans;
}
void Test()
{
cin >> n >> m >> p >> k;
cout << pw(p * k % M , (n - 1) * (m - 1)) * pw(p , n + m - 1) % M << '\n';
}
signed main()
{
#ifndef ONLINE_JUDGE
// FastIO , FILES;
#endif
int q; cin >> q;
while(q--) Test();
return 0;
}