def matrix_mul(A,B,mod = None): nA = len(A) mA = len(A[0]) mB = len(B[0]) tmp = [[0]*mB for _ in range(nA)] if mod is None: for i in range(nA): for j in range(mB): tmp[i][j] = sum(A[i][k]*B[k][j] for k in range(mA)) return tmp for i in range(nA): for j in range(mB): tmp[i][j] = sum(A[i][k]*B[k][j]%mod for k in range(mA))%mod return tmp def matrix_pow(A,n,mod = None): nbit = list(str(bin(n))[2:]) nbit = [int(i) for i in nbit] N = len(A) C = [[0]*N for _ in range(N)] B = A for i in range(N): C[i][i] = 1 if mod is None: for i in range(len(nbit)): if nbit[-1-i] == 1: C = matrix_mul(C,B) B = matrix_mul(B,B) return C for i in range(len(nbit)): if nbit[-1-i] == 1: C = matrix_mul(C,B,mod) B = matrix_mul(B,B,mod) return C A,B = map(int,input().split()) N = int(input()) X = [[1,0,0],[A,0,B],[0,0,1]] Y = [[0,1,0],[0,0,0],[1,0,0]] mod = 10**9 + 7 Z = matrix_mul(Y,X,mod) for _ in range(N): t = int(input()) m,r = divmod(t,2) INIT = [[1],[0],[1]] if r == 0: ans = matrix_mul(matrix_pow(Z,m,mod),INIT,mod) else: ans = matrix_mul(matrix_mul(X,matrix_pow(Z,m,mod),mod),INIT,mod) print(sum(ans[i][0] for i in range(3))%mod)