#include using namespace std; using ll = long long; using P = pair; #define rep(i, n) for(int i = 0; i < n; i++) #define all(x) (x).begin(),(x).end() templatebool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;} templatebool chmax(T&a, const T&b){if(a vector> MatrixProduct(vector> vec1, vector> vec2){ int N = vec1.size(), M = vec2[0].size(), L = vec2.size(); vector> res(N,vector(M,0)); rep(i,N) rep(j,M) rep(k,L) res[i][j] = (res[i][j] + vec1[i][k] * vec2[k][j])%MOD; return res; } int main(){ ll a,b,n; cin >> a >> b >> n; rep(i,n){ vector> o = { {1,0,0}, {0,1,0}, {a,b,1} }; vector> e = { {0,0,1}, {1,0,0}, {0,0,0} }; auto oe = MatrixProduct(e,o); vector> cookie = {{1},{1},{0}}; ll t; cin >> t; bool b = t%2; t >>= 1; while(t){ if(t&1) cookie = MatrixProduct(oe, cookie); t >>= 1; oe = MatrixProduct(oe,oe); } if(b) cookie = MatrixProduct(o, cookie); ll ans = 0; rep(i,3){ ans = (ans + cookie[i][0]) % MOD; } cout << ans << endl; } return 0; }