#include using namespace std; typedef long long int ll; typedef pair P; typedef vector VI; typedef vector VVI; #define REP(i,n) for(ll i=0;i<(n);i++) #define ALL(v) v.begin(),v.end() template bool chmax(T &x, const T &y) {return (x bool chmin(T &x, const T &y) {return (x>y)?(x=y,true):false;}; constexpr ll MOD=1000000007; constexpr ll INF=2e18; VVI matmult(VVI a, VVI b){ int p=a.size(), q=b[0].size(), r=a[0].size(); VVI ret(p,VI(q)); REP(i,p)REP(j,q){ ll sum=0; REP(k,r){ sum=(sum+a[i][k]*b[k][j]%MOD)%MOD; } ret[i][j]=sum; } return ret; } VVI matpower(VVI x, ll y){ int n=x.size(); VVI ret(n,VI(n,0)); REP(i,n) ret[i][i]=1; while(y){ if(y&1) ret=matmult(ret,x); x=matmult(x,x); y>>=1; } return ret; } int main(){ ll a, b; cin >> a >> b; VVI x={{1,0,0},{0,1,0},{a,b,1}}; VVI y={{0,0,1},{1,0,0},{0,0,0}}; VVI z=matmult(y,x); int n; cin >> n; ll t; REP(i,n){ cin >> t; VVI m=matpower(z,t/2); if(t%2==1) m=matmult(x,m); VVI a={{1},{1},{0}}; a=matmult(m,a); cout << (a[0][0]+a[1][0]+a[2][0])%MOD << endl; } return 0; }