/* WA: Overflow */ #include #include constexpr int MOD = 1'000'000'007; struct matrix_t { using i64 = int; std::vector> matrix; matrix_t(): matrix(3, std::vector(3)) {} matrix_t(const std::vector>& matrix): matrix(matrix) {} static matrix_t E() { return matrix_t({{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}); } std::vector& operator[](int k) { return matrix[k]; } inline matrix_t operator*(const matrix_t& r) const { matrix_t ret; for(size_t i = 0; i < 3; i++) { for(size_t j = 0; j < 3; j++) { for(size_t k = 0; k < 3; k++) { (ret[i][j] += matrix[i][k] * r.matrix[k][j]) %= MOD; } } } return std::move(ret); } inline matrix_t operator^=(i64 k) { matrix_t tmp = E(); while(k) { if(k & 1) tmp = tmp * (*this); (*this) = (*this) * (*this); k >>= 1; } matrix.swap(tmp.matrix); return *this; } }; int main() { int A, B, N; scanf("%d%d%d", &A, &B, &N); using i64 = long long; while(N--) { i64 T; scanf("%lld", &T); matrix_t matrix({{A, B, 1}, {1, 0, 0}, {0, 0, 0}}); matrix ^= T / 2; if(T % 2) { matrix = matrix_t({{1, 0, 0}, {0, 1, 0}, {A, B, 1}}) * matrix; } int ans = 0; for(size_t i = 0; i < 3; i++) for(size_t j = 0; j < 2; j++) ans = (ans + matrix[i][j]) % MOD; printf("%d\n", ans); } return 0; }