#include #include #include using namespace std; typedef long long ll; const ll MOD = 1000000007; template struct Matrix { using F = function; int n; int m; vector> a; const F add; const F mul; const T e0; const T e1; Matrix( int n, int m, const F add = [](T a, T b){return (a + b) % MOD;}, const F mul = [](T a, T b){return a * b % MOD;}, const T e0 = 0, const T e1 = 1 ) : n(n), m(m), add(add), mul(mul), e0(e0), e1(e1){ a.resize(n); for(int i = 0; i < n; i++) a[i].resize(m); } Matrix( int n, const F add = [](T a, T b){return (a + b) % MOD;}, const F mul = [](T a, T b){return a * b % MOD;}, const T e0 = 0, const T e1 = 1 ) : n(n), m(n), add(add), mul(mul), e0(e0), e1(e1){ a.resize(n); for(int i = 0; i < n; i++) a[i].resize(m); } static Matrix I( int n, const F add = [](T a, T b){return (a + b) % MOD;}, const F mul = [](T a, T b){return a * b % MOD;}, const T e0 = 0, const T e1 = 1 ){ Matrix res(n, add, mul, e0, e1); for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++) res.a[i][j] = e0; } for(int i = 0; i < n; i++) res.a[i][i] = e1; return res; } Matrix &operator+=(const Matrix &b){ for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++) a[i][j] = add(a[i][j], b.a[i][j]); } return *this; } Matrix &operator*=(const Matrix &b){ vector> c(n, vector(b.m)); for(int i = 0; i < n; i++){ for(int j = 0; j < b.m; j++){ c[i][j] = e0; for(int k = 0; k < m; k++){ c[i][j] = add(c[i][j], mul(a[i][k], b.a[k][j])); } } } a.swap(c); return *this; } Matrix &operator^=(long long k){ Matrix b = Matrix::I(n, add, mul, e0, e1); while(k){ if(k % 2) b *= *this; *this *= *this; k /= 2; } a.swap(b.a); return *this; } Matrix operator+(const Matrix &a){ return (Matrix(*this) += a); } Matrix operator*(const Matrix &a){ return (Matrix(*this) *= a); } Matrix operator^(const long long k){ return (Matrix(*this) ^= k); } }; int main() { ll a, b; ll n; cin >> a >> b >> n; Matrix A(6); A.a[0][5] = 1; A.a[1][3] = 1; A.a[3][0] = 1; A.a[4][1] = 1; A.a[5][0] = a; A.a[5][1] = b; A.a[5][2] = 1; while(n--){ ll t; cin >> t; Matrix B = A ^ t; ll ans = 0; for(int i = 0; i < 6; i++) ans = (ans + B.a[i][0] + B.a[i][1]) % MOD; cout << ans << endl; } }