#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int f[1009][1009];
const int mod = 10007;
int a,b,k,n,m;
int main() {
freopen("factor.in","r",stdin);
freopen("factor.out","w",stdout);
cin >> a >> b >> k >> n >> m;
f[0][0] = 1;
for (int i = 1;i <= n; i++)
f[i][0] = f[i-1][0]*a%mod;
for (int j = 1; j <= m; j++)
f[0][j] = f[0][j-1]*b%mod;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
f[i][j] = (f[i-1][j]*a+f[i][j-1]*b)%mod;
cout<<f[n][m];
return 0;
}