import sys input = sys.stdin.readline MOD = 10 ** 9 + 7 class Matrix: def __init__(self, A: list): if not(A and isinstance(A[0], list)): A = [A] self.A = A self.row = len(A) self.col = len(A[0]) self.I = None if(self.row == self.col): self.I = [[0] * self.col for _ in [0] * self.row] for i in range(self.row): self.I[i][i] = 1 def set_A(self, A: list) -> None: self.A = A def set_I(self, I) -> None: self.I = I def __str__(self): return str(self.A) __repr__ = __str__ def __add__(self, other): ret = Matrix(self) for i in range(self.row): for j in range(self.col): ret.A[i][j] = self.A[i][j] + other.A[i][j] ret.A[i][j] %= MOD return ret def __sub__(self, other): ret = Matrix(self) for i in range(self.row): for j in range(self.col): ret.A[i][j] = self.A[i][j] - other.A[i][j] ret.A[i][j] %= MOD return ret def __mul__(self, other): assert(self.col == other.row) ret = Matrix([[0]*other.col for _ in [0]*self.row]) for i in range(self.row): for j in range(other.col): ret.A[i][j] = sum(self.A[i][k] * other.A[k][j] % MOD for k in range(self.col)) ret.A[i][j] %= MOD return ret def __pow__(self, other: int): mat = self ret = Matrix(self.I) n = other while(n): if(n & 1): ret = mat * ret mat = mat * mat n >>= 1 return ret ''' Main Code ''' a, b = map(int, input().split()) A = Matrix([[a, b], [1, 0]]) v = Matrix([[1], [1]]) n = int(input()) for _ in [0] * n: t = int(input()) d = t // 2; r = t % 2 v1 = (A ** d) * v v2 = A * v1 ans = 0 if(r == 1): ans = (v1.A[0][0] + v1.A[1][0] + v2.A[0][0]) % MOD else: ans = (v1.A[0][0] + v1.A[1][0]) % MOD print(ans)