import numpy as np MOD = 10 ** 9 + 7 def pow_matrix_mod(x, n, mod=MOD): if not n: return np.eye(len(x), dtype=object) if n % 2 == 0: return pow_matrix_mod(x @ x % mod, n // 2) % mod else: return x @ pow_matrix_mod(x @ x % mod, (n - 1) // 2) % mod A, B = map(int, input().split()) matr_odd = np.array([[1, 0, A], [0, 1, B], [0, 0, 1]], dtype=object) matr_even = np.array([[0, 1, 0], [0, 0, 0], [1, 0, 0]], dtype=object) matr = (matr_odd @ matr_even) % MOD N = int(input()) for _ in range(N): T = int(input()) p = pow_matrix_mod(matr, T // 2) if T % 2: p = p @ matr_odd p %= MOD ans = np.sum(np.array([1, 1, 0]) @ p) % MOD print(ans)