#include #include #define rep(i, n) for (int i = 0; i < n; ++i) typedef long long ll; using namespace atcoder; using namespace std; using mint = modint1000000007; template struct Matrix { vector> A; Matrix() {} Matrix(int H, int W) : A(H, vector(W, 0)) {} inline const vector &operator[](int i) const { return A.at(i); } inline vector &operator[](int i) { return A.at(i); } int get_height() const { return A.size(); } int get_width() const { return A[0].size(); } inline T add(T a, T b) { return a + b; } inline T mul(T a, T b) { return a * b; } T e = 1; Matrix &operator+=(const Matrix &A) { int H = get_height(), W = get_width(); assert(H == A.get_height() && W == A.get_width()); rep(i, H) rep(j, W)(*this)[i][j] = add((*this)[i][j], A[i][j]); return (*this); } Matrix &operator*=(const Matrix &B) { int H = get_height(), W = B.get_width(), Z = get_width(); assert(Z == B.get_height()); vector> C(H, vector(W)); rep(i, H) rep(j, W) rep(k, Z) C[i][j] = add(C[i][j], mul((*this)[i][k], B[k][j])); (*this).A = C; return (*this); } Matrix &operator^=(ll k) { int N = get_height(); Matrix B(N, N); rep(i, N) B.A[i][i] = e; while (k > 0) { if (k & 1) B *= (*this); (*this) *= (*this); k >>= 1LL; } (*this) = B; return (*this); } Matrix operator+(const Matrix &B) const { return Matrix(*this) += B; } Matrix operator*(const Matrix &B) const { return Matrix(*this) *= B; } Matrix operator^(ll k) const { return Matrix(*this) ^= k; } }; int main() { cin.tie(0)->sync_with_stdio(0); ll A, B; int N; cin >> A >> B >> N; Matrix MA(3, 3), MB(3, 3); MA.A = {{1, A, B}, {0, 1, 0}, {0, 0, 1}}; MB.A = {{0, 0, 0}, {1, 0, 0}, {0, 1, 0}}; Matrix MC = MB * MA; rep(i, N) { ll T; cin >> T; Matrix init(3, 1); init.A = {{0}, {1}, {1}}; Matrix M = (MC ^ (T / 2)) * init; mint ans = M[1][0] + M[2][0]; if (T % 2 == 1) ans += M[1][0] * A + M[2][0] * B; cout << ans.val() << "\n"; } return 0; }