#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MOD 1000000007
#define MAXN 2100000
typedef long long qword;
struct matrix
{
qword a[2][2];
int n,m;
matrix()
{
memset(a,0,sizeof(a));
}
void init0()
{
n=m=2;
a[0][0]=a[1][1]=1;
a[0][1]=a[1][0]=0;
}
void init1(int aa,int bb)
{
n=m=2;
a[0][0]=aa;
a[0][1]=bb;
a[1][1]=1;
}
void init2(int aa)
{
n=2;m=1;
a[0][0]=aa;
a[1][0]=1;
}
};
inline matrix operator *(matrix m1,matrix m2)
{
int i,j,k;
matrix ret;
ret.n=m1.n;
ret.m=m2.m;
if (ret.n==2 && ret.m==2)
{
if (m1.a[1][1]!=1 || m1.a[1][0]!=0 || m2.a[1][1]!=1 || m2.a[1][0]!=0)
throw 1;
ret.a[0][0]=m1.a[0][0]*m2.a[0][0]%MOD;
ret.a[0][1]=(m1.a[0][0]*m2.a[0][1]%MOD+m1.a[0][1])%MOD;
ret.a[1][0]=0;
ret.a[1][1]=1;
return ret;
}
for (i=0;i<m1.n;i++)
{
for (j=0;j<m2.m;j++)
{
for (k=0;k<m1.m;k++)
{
ret.a[i][j]=(ret.a[i][j]+m1.a[i][k]*m2.a[k][j]%MOD)%MOD;
}
}
}
return ret;
}
matrix pow_mod(matrix a,char *str,int len)
{
int i,j;
register matrix t,l0,ret;
ret.init0();
l0.init0();
t=a;
for (i=len-1;i>=0;i--)
{
for (j=0;j<10;j++)
{
if (j==str[i]-‘0‘)
ret=ret*l0;
l0=l0*t;
}
t=l0;
l0.init0();
}
return ret;
}
char s1[MAXN],s2[MAXN];
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
qword a,b,c,d,i,j,k;
scanf("%s %s%lld%lld%lld%lld",s1,s2,&a,&b,&c,&d);
a%=MOD;b%=MOD;c%=MOD;d%=MOD;
int l1,l2;
l1=strlen(s1);
l2=strlen(s2);
int x;
x=l1-1;
s1[x]--;
while (s1[x]<‘0‘)
{
s1[x]+=10;s1[x-1]--;x--;
}
x=l2-1;
s2[x]--;
while (s2[x]<‘0‘)
{
s2[x]+=10;s2[x-1]--;x--;
}
matrix m1,r1,m2,r2,r3,m3,r4,m4;
matrix t1;
m1.init1(a,b);
m2.init1(c,d);
m4.init2(1);
r1=pow_mod(m1,s2,l2);
r2=m2*r1;
r3=pow_mod(r2,s1,l1);
r4=r1*r3*m4;
cout<<r4.a[0][0]<<endl;
}