A,B = map(int,input().split()) N = int(input()) P = 10 ** 9 + 7 R = [[A,B,1],[1,0,0],[0,0,0]] S = [[1,0,0,],[0,1,0],[A,B,0]] def seki(X,Y): l = [[0] *3 for _ in range(3)] for i in range(3): for j in range(3): for k in range(3): l[i][j] = (l[i][j] + X[i][k] * Y[k][j]) % P return l for _ in range(N): t = int(input()) q = t // 2 r = t % 2 tmp = [[1,0,0,],[0,1,0],[0,0,1]] Rnow = R while q: if q & 1: tmp = seki(R,tmp) q >>= 1 Rnow = seki(Rnow,Rnow) if r: tmp = seki(S,tmp) ans = tmp[0][0] + tmp[0][1] + tmp[1][0] + tmp[1][1] + tmp[2][0] + tmp[2][1] print(ans % P)