#include #include using namespace std; using mint = atcoder::modint1000000007; using vec = vector; using mat = vector; vec mul(mat a, vec b) { vec c(a.size()); for (int i = 0; i < a.size(); i++) { for (int j = 0; j < b.size(); j++) { c[i] += a[i][j] * b[j]; } } return c; } mat mul(mat a, mat b) { mat c(a.size(), vec(b[0].size())); for (int i = 0; i < a.size(); i++) { for (int j = 0; j < b.size(); j++) { for (int k = 0; k < b[0].size(); k++) { c[i][k] += a[i][j] * b[j][k]; } } } return c; } mat mat_pow(mat a, long long n) { mat res(a.size(), vec(a.size())); for (int i = 0; i < a.size(); i++) { res[i][i] = 1; } while (n) { if (n & 1) res = mul(res, a); a = mul(a, a); n >>= 1; } return res; } void fast_io() { ios::sync_with_stdio(false); std::cin.tie(nullptr); } int main() { fast_io(); int a, b; cin >> a >> b; mat A = {{a, b}, {1, 0}}; int n; cin >> n; for (; n--;) { long long t; cin >> t; auto res = mul(mat_pow(A, t / 2), vec{1, 1}); if (t % 2 == 0) { mint ans = res[0] + res[1]; cout << ans.val() << "\n"; } else { mint ans = (a + 1) * res[0] + (b + 1) * res[1]; cout << ans.val() << "\n"; } } }