L=3 M=10**9+7 def seki(a,b): c=[[0]*L for i in range(L)] for i in range(L): for j in range(L): for k in range(L): c[i][j]+=a[i][k]*b[k][j] c[i][j]%=M return c a,b=map(int,input().split()) A0=[[0,0,1],[1,0,0],[0,0,0]] A1=[[1,0,0],[0,1,0],[a,b,1]] n=int(input()) for _ in range(n): t=int(input()) A=seki(A0,A1) B=[[1,0,0],[0,1,0],[0,0,1]] for i in range(61): if ((t//2)>>i)&1: B=seki(A,B) A=seki(A,A) if t%2: B=seki(A1,B) print(sum(B[i][0]+B[i][1] for i in range(L))%M)