#include<bits/stdc++.h> #define P 1000000007 usingnamespace std; typedeflonglong lnt; template <classT> inlinevoidread(T &x){ x = 0; int c = getchar(), f = 1; for (; !isdigit(c); c = getchar()) if (c == 45) f = -1; for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-'0'); } template <classT> inlinevoidread_sup(T &x, T &y){ x = y = 0; int c = getchar(), f = 1; for (; !isdigit(c); c = getchar()) if (c == 45) f = -1; for (; isdigit(c); c = getchar()) x = (x*10+f*(c-'0'))%P, y = (y*10+f*(c-'0'))%(P-1); } lnt n0, n1, m0, m1, a, b, c, d, x, y, z, f; lnt Pow(lnt x, lnt k){ lnt ret = 1; if (k < 0) k += (P-1); for (; k; k >>= 1, x = x*x%P) if (k&1) ret = ret*x%P; return ret; } lnt Inv(lnt x){returnPow(x, P-2);} intmain(){ read_sup(n0, n1), read_sup(m0, m1); read(a), read(b), read(c), read(d); x = Pow(a, m1-1)*c%P, z = ((P+m0-1)%P*b%P*c%P+d)%P; y = ((Pow(a, m1-1)+P-1)%P*b%P*c%P*Inv(a-1)%P+d)%P; if (a == 1 && c == 1) f = (1+z*n0%P)%P; elseif (a == 1 && c > 1) f = (Pow(c, n1)+(Pow(c, n1)+P-1)%P*Inv(c-1)%P*z%P)%P; else f = (Pow(x, n1)+(Pow(x, n1)+P-1)%P*Inv(x-1)%P*y%P)%P; f = (f+P-d)%P*Inv(c)%P; returnprintf("%lld\n", f), 0; }