n,a,b,k=map(int,input().split()) if not 1<=n<=10**18:exit() if not 1<=a<=10**9:exit() if not 1<=b<=10**9:exit() if not 1<=k<=10**9:exit() m=10**9+7 s = (a*a+b*b+k)%m s = (s*pow(a,-1,m))%m s = (s*pow(b,-1,m))%m z=[[s,-1],[1,0]] mod=10**9+7 def ff(a,b): return a[0]*b[0]+a[1]*b[1] #a*bの計算 def mat_mul(a,b): n,m,l=len(a),len(b[0]),len(b) c=[[0]*m for _ in range(n)] for i in range(n): for k in range(l): for j in range(m): c[i][j]=(c[i][j]+a[i][k]*b[k][j])%mod return c #a^nの計算 def mat_pow(a,n): m=len(a) b=[[0]*m for _ in range(m)] for i in range(m): b[i][i]=1 while n>0: if n&1: b=mat_mul(b,a) a=mat_mul(a,a) n>>=1 return b #print(z) if n>=3: ans=mat_pow(z,n-2) print(ff(ans[0],[b,a])%mod) #print(ans) #print(b) else: if n==1: print(a) else: print(b)