a,b = map(int,input().split()) mod = 10**9+7 def calc(x,y): ans = [[0]*3 for i in range(3)] for i in range(3): for j in range(3): for k in range(3): ans[i][j] += x[i][k]*y[k][j] ans[i][j] %= mod return ans def solve(): t = int(input()) base = [[0]*3 for i in range(3)] for i in range(3): base[i][i] = 1 A = [[1,0,0],[0,1,0],[a,b,0]] B = [[0,0,1],[1,0,0],[0,0,0]] C = calc(B,A) now = t//2 while now: if now & 1: base = calc(C,base) C = calc(C,C) now //= 2 if t & 1: base = calc(A,base) ans = 0 for i in range(3): for j in range(2): ans += base[i][j] return ans%mod n = int(input()) for i in range(n): print(solve())