#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1000000007;
int n, m, a, b, c, d, f[1010][1010];
signed main() {
freopen("matrixb.in", "r", stdin);
freopen("matrixb.out", "w", stdout);
cin >> n >> m >> a >> b >> c >> d;
f[1][1] = 1;
for(int i = 1; i <= n; i ++) {
if(i != 1) {
f[i][1] = f[i - 1][m] * c + d;
f[i][1] %= mod;
}
for(int j = 2; j <= m; j ++) {
f[i][j] = f[i][j - 1] * a + b;
f[i][j] %= mod;
}
}
cout << f[n][m];
return 0;
}