#include <bits/stdc++.h>
using namespace std;
typedef long long L;
class compare {
public:
bool operator() (const pair<int,int> a, const pair<int,int> b) {
return a.first > b.first;
}
};
const int mod = 1000000007;
const int N = 100004;
const int inf = 1000000000;
inline L add(L a, L b, L MOD) {
L res = a + b;
while(res >= MOD) {
res -= MOD;
}
return res;
}
inline L mul(L a, L b, L MOD) {
L res = a * b;
if(res >= MOD) res %= MOD;
return res;
}
inline L power(L a, L b) {
L res = 1;
while(b > 0) {
if(b & 1) {
res = mul(res, a, mod);
}
a = mul(a, a, mod);
b /= 2;
}
return res;
}
int lp[N], a[N];
set <pair<int,int>, compare> poss[N];
int posMax[N] = {0};
map <int,int> mp;
struct Node {
Node * l, *r;
int prod;
Node(int p = 1) : l(0), r(0), prod(p) {}
Node(Node* l, Node* r) : l(l), r(r), prod(1) {
if(l) {
prod = mul(prod, l->prod, mod);
}
if(r) {
prod = mul(prod, r->prod, mod);
}
}
} store[100 * N];
int strCnt = 0;
Node* Fun(int val) {
Node* res = &store[strCnt++];
assert (strCnt < 100 * N);
res->l = 0;
res->r = 0;
res->prod = val;
return res;
}
Node* Fun1(Node* ll, Node* rr) {
Node* res = &store[strCnt++];
assert (strCnt < 100 * N);
res->prod = 1;
res->l = ll;
res->r = rr;
if (ll) {
res->prod = mul(res->prod, ll->prod, mod);
}
if (rr) {
res->prod = mul(res->prod, rr->prod, mod);
}
return res;
}
vector <Node*> head;
Node* build(int b, int e) {
if(b == e) {
return Fun(1);
}
int mid = (b + e)/2;
return new Node(build(b, mid), build(mid+1, e));
}
int query(Node* v, int b, int e, int l, int r) {
if(b > r || e < l) {
return 1;
}
if(b >= l && e <= r) {
return v->prod;
}
int mid = (b + e)/2;
return mul(query(v->l, b, mid, l, r), query(v->r, mid+1, e, l, r), mod);
}
Node* update(Node* v, int b, int e, int pos, int val) {
if(b == e) {
return Fun(val);
}
int mid = (b + e)/2;
if(pos <= mid) {
return Fun1(update(v->l, b, mid, pos, val), v->r);
} else {
return Fun1(v->l, update(v->r, mid+1, e, pos, val));
}
}
int query1(Node* v, int b, int e, int pos) {
if(b == e) {
return v->prod;
}
int mid = (b + e)/2;
if(pos <= mid) {
return query1(v->l, b, mid, pos);
} else {
return query1(v->r, mid+1, e, pos);
}
}
void updateMap(int posx, int val) {
if(!mp.count(posx)) {
mp[posx] = 1;
}
mp[posx] = mul(mp[posx], val, mod);
}
int main()
{
int n, q;
scanf("%d %d", &n, &q);
assert(1 <= n && n <= 100000);
assert(1 <= q && q <= 1000000);
fill(lp, lp + N, inf);
for(L i = 2; i < N; ++i) {
if(lp[i] == inf) {
lp[i] = i;
for(L j = i * i; j < N; j += i) {
lp[j] = min(lp[j], (int)i);
}
}
}
for (int i = 1; i <= n; ++i) {
scanf("%d", a + i);
assert (1 <= a[i] && a[i] <= 100000);
}
int aa, bb, gg, dd;
scanf("%d %d %d %d", &aa, &bb, &gg, &dd);
assert (0 <= aa && aa <= 1000000000);
assert (0 <= bb && bb <= 1000000000);
assert (0 <= gg && gg <= 1000000000);
assert (0 <= dd && dd <= 1000000000);
head.resize(N);
head[0] = build(1, n);
for(int i = 1; i <= n; ++i) {
L cur = a[i], toAdd = 1;
mp.clear();
for(L p = lp[cur]; p * p <= cur; p = lp[cur]) {
int cont = 0;
while(cur % p == 0) {
cur /= p;
cont++;
}
int left = cont;
while(!poss[p - 1].empty() && left > 0) {
if(left == 0) break;
if(poss[p - 1].begin()->second <= 0) {
poss[p - 1].erase(poss[p - 1].begin());
continue;
}
int posx = poss[p - 1].begin()->first;
int coun = poss[p - 1].begin()->second;
updateMap(posx, power(p - 1, mod - 2));
poss[p - 1].erase(poss[p - 1].begin());
poss[p - 1].insert({posx, coun-1});
left--;
}
poss[p - 1].insert({i, cont});
posMax[p - 1] = max(posMax[p - 1], cont);
toAdd = mul(toAdd, power(p - 1, cont), mod);
}
if(cur > 1) {
L p = cur;
int cont = 1;
int left = cont;
while(!poss[p - 1].empty() && left > 0) {
if(left == 0) break;
if(poss[p - 1].begin()->second <= 0) {
poss[p - 1].erase(poss[p - 1].begin());
continue;
}
int posx = poss[p - 1].begin()->first;
int coun = poss[p - 1].begin()->second;
updateMap(posx, power(p - 1, mod - 2));
poss[p - 1].erase(poss[p - 1].begin());
poss[p - 1].insert({posx, coun-1});
left--;
}
poss[p - 1].insert({i, cont});
posMax[p - 1] = max(posMax[p - 1], cont);
toAdd = mul(toAdd, power(p - 1, cont), mod);
}
head[i] = update(head[i - 1], 1, n, i, toAdd);
if(!mp.empty()) {
for(pair<int,int> vv : mp) {
int val = query1(head[i], 1, n, vv.first);
head[i] = update(head[i], 1, n, vv.first, mul(val, vv.second, mod));
}
}
}
int last = 0;
for (int i = 1; i <= q; ++i) {
int l = 1 + add(mul(last, aa, n), mul(bb, i, n), n);
int r = l + add(mul(last, gg, n - l + 1), mul(dd, i, n - l + 1), n - l + 1);
assert (1 <= l && l <= r && r <= n);
int ans = query(head[r], 1, n, l, r);
printf("%d\n", ans);
last = ans;
}
return(0);
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiAKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnR5cGVkZWYgbG9uZyBsb25nIEw7CiAKY2xhc3MgY29tcGFyZSB7CiAgcHVibGljOgogIGJvb2wgb3BlcmF0b3IoKSAoY29uc3QgcGFpcjxpbnQsaW50PiBhLCBjb25zdCBwYWlyPGludCxpbnQ+IGIpIHsKICAgIHJldHVybiBhLmZpcnN0ID4gYi5maXJzdDsKICB9Cn07CiAKY29uc3QgaW50IG1vZCA9IDEwMDAwMDAwMDc7CmNvbnN0IGludCBOID0gMTAwMDA0Owpjb25zdCBpbnQgaW5mID0gMTAwMDAwMDAwMDsKIAppbmxpbmUgTCBhZGQoTCBhLCBMIGIsIEwgTU9EKSB7CiAgTCByZXMgPSBhICsgYjsKICB3aGlsZShyZXMgPj0gTU9EKSB7CiAgICByZXMgLT0gTU9EOwogIH0KICByZXR1cm4gcmVzOwp9CiAKaW5saW5lIEwgbXVsKEwgYSwgTCBiLCBMIE1PRCkgewogIEwgcmVzID0gYSAqIGI7CiAgaWYocmVzID49IE1PRCkgcmVzICU9IE1PRDsKICByZXR1cm4gcmVzOwp9IAogCmlubGluZSBMIHBvd2VyKEwgYSwgTCBiKSB7CiAgTCByZXMgPSAxOwogIHdoaWxlKGIgPiAwKSB7CiAgICBpZihiICYgMSkgewogICAgICByZXMgPSBtdWwocmVzLCBhLCBtb2QpOwogICAgfQogICAgYSA9IG11bChhLCBhLCBtb2QpOwogICAgYiAvPSAyOwogIH0KICByZXR1cm4gcmVzOwp9CgppbnQgbHBbTl0sIGFbTl07CiAKc2V0IDxwYWlyPGludCxpbnQ+LCBjb21wYXJlPiBwb3NzW05dOwppbnQgcG9zTWF4W05dID0gezB9OwptYXAgPGludCxpbnQ+IG1wOwoKc3RydWN0IE5vZGUgewogIE5vZGUgKiBsLCAqcjsKICBpbnQgcHJvZDsKICBOb2RlKGludCBwID0gMSkgOiBsKDApLCByKDApLCBwcm9kKHApIHt9CiAgTm9kZShOb2RlKiBsLCBOb2RlKiByKSA6IGwobCksIHIociksIHByb2QoMSkgewogICAgaWYobCkgewogICAgICBwcm9kID0gbXVsKHByb2QsIGwtPnByb2QsIG1vZCk7CiAgICB9CiAgICBpZihyKSB7CiAgICAgIHByb2QgPSBtdWwocHJvZCwgci0+cHJvZCwgbW9kKTsKICAgIH0KICB9Cn0gc3RvcmVbMTAwICogTl07CmludCBzdHJDbnQgPSAwOwoKTm9kZSogRnVuKGludCB2YWwpIHsKICBOb2RlKiByZXMgPSAmc3RvcmVbc3RyQ250KytdOwogIGFzc2VydCAoc3RyQ250IDwgMTAwICogTik7CiAgcmVzLT5sID0gMDsKICByZXMtPnIgPSAwOwogIHJlcy0+cHJvZCA9IHZhbDsKICByZXR1cm4gcmVzOwp9CgpOb2RlKiBGdW4xKE5vZGUqIGxsLCBOb2RlKiBycikgewogIE5vZGUqIHJlcyA9ICZzdG9yZVtzdHJDbnQrK107CiAgYXNzZXJ0IChzdHJDbnQgPCAxMDAgKiBO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cG93ZXIocCAtIDEsIG1vZCAtIDIpKTsKICAgICAgICBwb3NzW3AgLSAxXS5lcmFzZShwb3NzW3AgLSAxXS5iZWdpbigpKTsKICAgICAgICBwb3NzW3AgLSAxXS5pbnNlcnQoe3Bvc3gsIGNvdW4tMX0pOwogICAgICAgIGxlZnQtLTsKICAgICAgfQogICAgICAgIAogICAgICBwb3NzW3AgLSAxXS5pbnNlcnQoe2ksIGNvbnR9KTsKICAgICAgcG9zTWF4W3AgLSAxXSA9IG1heChwb3NNYXhbcCAtIDFdLCBjb250KTsKICAgICAgdG9BZGQgPSBtdWwodG9BZGQsIHBvd2VyKHAgLSAxLCBjb250KSwgbW9kKTsKICAgIH0KICAgIAogICAgaWYoY3VyID4gMSkgewogICAgICBMIHAgPSBjdXI7CiAgICAgIGludCBjb250ID0gMTsKICAgICAgCiAgICAgIGludCBsZWZ0ID0gY29udDsKICAgICAgd2hpbGUoIXBvc3NbcCAtIDFdLmVtcHR5KCkgJiYgbGVmdCA+IDApIHsKICAgICAgICBpZihsZWZ0ID09IDApIGJyZWFrOwogICAgICAgIGlmKHBvc3NbcCAtIDFdLmJlZ2luKCktPnNlY29uZCA8PSAwKSB7CiAgICAgICAgICBwb3NzW3AgLSAxXS5lcmFzZShwb3NzW3AgLSAxXS5iZWdpbigpKTsKICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgIH0KICAgICAgICBpbnQgcG9zeCA9IHBvc3NbcCAtIDFdLmJlZ2luKCktPmZpcnN0OwogICAgICAgIGludCBjb3VuID0gcG9zc1twIC0gMV0uYmVnaW4oKS0+c2Vjb25kOwogICAgICAgIHVwZGF0ZU1hcChwb3N4LCBwb3dlcihwIC0gMSwgbW9kIC0gMikpOwogICAgICAgIHBvc3NbcCAtIDFdLmVyYXNlKHBvc3NbcCAtIDFdLmJlZ2luKCkpOwogICAgICAgIHBvc3NbcCAtIDFdLmluc2VydCh7cG9zeCwgY291bi0xfSk7CiAgICAgICAgbGVmdC0tOwogICAgICB9CiAgIC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