#include #include #define rep(i, l, n) for (int i = (l); i < (n); i++) using namespace std; using ll = long long; template using V = vector; template using VV = V >; const ll mod = 1000000007; VV matrix_prod(const VV&A, const VV&B) { VV res = { {0,0},{0,0} }; rep(i, 0, 2) { rep(j, 0, 2) { rep(k, 0, 2) { res[i][j] += A[i][k] * B[k][j]; res[i][j] %= mod; } } } return res; } VV matrix_exp(VVA, ll n) { VV res = { {1,0},{0,1} }; while (n) { if (n & 1) { res = matrix_prod(A, res); } A = matrix_prod(A, A); n >>= 1; } return res; } V P_convertion(const VV& A, const V& v) { V res = { 0,0 }; rep(i, 0, 2) { rep(j, 0, 2) { res[i] += A[i][j] * v[j]; res[i] %= mod; } } return res; } int main(void) { ll a, b; cin >> a >> b; int n; cin >> n; V t(n); rep(i, 0, n) { cin >> t[i]; } VV A = { {a,b},{1,0} }; V v = { 1,1 }; rep(i, 0, n) { ll d = t[i] >> 1; int r = t[i] & 1; VV Ad = matrix_exp(A, d); V v1 = P_convertion(Ad, v); V v2 = P_convertion(A, v1); if (r == 1) { cout << ((v1[0] + v1[1] + v2[0]) % mod) << endl; } else { cout << ((v1[0] + v1[1]) % mod) << endl; } } return 0; }