#include #define DIM 3 const int Mod = 1000000007; void copy_matrix(int d, long long A[][DIM], long long B[][DIM]) { int i, j; for (i = 0; i < d; i++) for (j = 0; j < d; j++) B[i][j] = A[i][j]; } void prod_matrix(int d, long long A[][DIM], long long B[][DIM], long long C[][DIM]) { int i, j, k; for (i = 0; i < d; i++) { for (j = 0; j < d; j++) { for (k = 0, C[i][j] = 0; k < d; k++) C[i][j] += A[i][k] * B[k][j] % Mod; C[i][j] %= Mod; } } } void pow_matrix(int d, long long A[][DIM], long long k, long long B[][DIM]) { int i, j; long long C[2][DIM][DIM], D[DIM][DIM]; copy_matrix(d, A, C[0]); for (i = 0; i < d; i++) for (j = 0; j < d; j++) B[i][j] = 0; for (i = 0; i < d; i++) B[i][i] = 1; for (i = 0, j = 1; k > 0; i ^= 1, j ^= 1, k >>= 1) { prod_matrix(d, C[i], C[i], C[j]); if (k % 2 == 1) { prod_matrix(d, B, C[i], D); copy_matrix(d, D, B); } } } void prod_matrix_vector(int d, long long A[][DIM], long long x[], long long y[]) { int i, j; for (i = 0; i < d; i++) { for (j = 0, y[i] = 0; j < d; j++) y[i] += A[i][j] * x[j] % Mod; y[i] %= Mod; } } int main() { int i, A, B, N; long long T[1001]; scanf("%d %d", &A, &B); scanf("%d", &N); for (i = 1; i <= N; i++) scanf("%lld", &(T[i])); long long C[DIM][DIM] = {{A, B, 1}, {1, 0, 0}, {0, 0, 0}}, CC[DIM][DIM], x[DIM] = {1, 1, 0}, y[DIM]; for (i = 1; i <= N; i++) { pow_matrix(3, C, T[i] / 2, CC); prod_matrix_vector(3, CC, x, y); if (T[i] % 2 == 0) printf("%lld\n", (y[0] + y[1] + y[2]) % Mod); else printf("%lld\n", (y[0] * (A + 1) + y[1] * (B + 1) + y[2]) % Mod); } fflush(stdout); return 0; }