/* * Author: nskybytskyi * Time: 2022-01-13 15:08:45 */ #include using namespace std; const int64_t mod = 1'000'000'007; using matrix = vector>; const matrix eye = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}; vector mmul(matrix lhs, vector rhs) { vector res(3); for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { res[i] += lhs[i][j] * rhs[j]; res[i] %= mod; } } return res; } matrix mmul(matrix lhs, matrix rhs) { matrix ans(3, vector(3, 0)); for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { for (int k = 0; k < 3; ++k) { ans[i][j] += lhs[i][k] * rhs[k][j]; ans[i][j] %= mod; } } } return ans; } matrix mpow(matrix base, int64_t exponent) { matrix res = eye; while (exponent) { if (exponent & 1) { res = mmul(res, base); } base = mmul(base, base); exponent >>= 1; } return res; } int main() { cin.tie(0)->sync_with_stdio(0); int a, b, n; cin >> a >> b >> n; vector> t(n); for (int i = 0; i < n; ++i) { cin >> t[i].first; t[i].second = i; } sort(t.begin(), t.end()); matrix e = {{1, 0, 0}, {0, 1, 0}, {a, b, 1}}, o = {{0, 0, 1}, {1, 0, 0}, {0, 0, 0}}; matrix eo = mmul(e, o), oe = mmul(o, e); vector curr = {1, 1, 0}; int64_t time = 0; vector ans(n); for (auto [ti, i] : t) { if (time & 1) { if (ti & 1) { curr = mmul(mpow(eo, (ti - time) / 2), curr); } else { curr = mmul(o, curr); curr = mmul(mpow(oe, (ti - time) / 2), curr); } } else { if (ti & 1) { curr = mmul(e, curr); curr = mmul(mpow(eo, (ti - time) / 2), curr); } else { curr = mmul(mpow(oe, (ti - time) / 2), curr); } } time = ti; ans[i] = (curr[0] + curr[1] + curr[2]) % mod; } for (auto elem : ans) { cout << elem << "\n"; } return 0; }