#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#define FOR(i,a,b) for(i=(a);i<=(b);i++)
#define ROF(i,a,b) for(i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define N 2000010
#define MOD 1000000007
using namespace std;
typedef long long LL;
typedef long double LD;
LL phimod;
struct bignum
{
char s[N];
LL getint()
{
int L=strlen(s+1),i;
LL x=0;
FOR(i,1,L)
{
x*=10;x+=s[i]-'0';
x%=phimod;
}
return x;
}
}ns,ms;
LL a,b,c,d;
LL powmod(LL x,LL P)
{
LL e=x,res=1;
for(;P;P>>=1) {if (P&1) res*=e,res%=MOD;e*=e,e%=MOD;}
return res;
}
LL sum(LL a,LL m) {
if (a==1) return m;
LL a_1=powmod(a-1,phimod-1);
return (powmod(a,m)-1)*a_1%MOD;
}
LL cc(LL n,LL x,LL a,LL b)
{
LL t1=powmod(a,n-1)*x%MOD;
LL t2=sum(a,n-1)*b%MOD;
return (t1+t2)%MOD;
}
int main()
{
ios::sync_with_stdio(false);
scanf("%s%s",ns.s+1,ms.s+1);
scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
if (a==1&&c==1) phimod=MOD;else phimod=MOD-1;
LL n=ns.getint(),m=ms.getint();
if (n==1) if (strcmp(ns.s+1,"1")!=0) n=MOD;
if (m==1) if (strcmp(ms.s+1,"1")!=0) m=MOD;
LL T=sum(a,m-1)*b%MOD;
LL dc=powmod(a,m-1);
LL nc=c,nd=d,fn1,fnm;
nc*=dc;nc%=MOD;
nd+=c*T%MOD;nd%=MOD;
fn1=cc(n,1,nc,nd);
fnm=cc(m,fn1,a,b);
printf("%lld\n",fnm);
return 0;
}