#include <iostream>
#include <stdio.h>
#include <math.h>
#include <map>
#include <vector>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include <set>
#define mod 1000000007
#define ll long long
#define pb push_back
#define mp make_pair
#include <queue>
using namespace std;
long long gcd( long long a , long long b )
{
return b == 0 ? a : gcd( b , a%b );
}
long long power( long long a , long long b )
{
long long ret = 1 ;
while( b ) {
if( b%2 == 1 ) ret = ( ret * a ) % mod ;
a = ( a * a ) % mod ;
b /= 2 ;
}
return ret ;
}
#define N 100010
int primes[ 333 ] , number[ N ];
bool isprime[ N ];
int arr[ N ] ;
char segtree[ 67 ][ 21 ][ N ];
#define mid(L,R) ((L+R)/2)
struct Node{ int cnt , L , R;
Node()
{
cnt = 1 ;
L = R = -1;
}
Node( int x,int y,int z)
{
L = x;
R = y;
cnt = z;
}
}tree[6000001];
int G[N];
int root[N] , RM[N] , B[N] , V[N] ;
int gc = 0 ;
int build(int L , int R)
{
++gc;
if( L == R )
return gc;
int x = gc;
tree[x] = Node(build(L,mid(L,R)),build(mid(L,R)+1,R),1);
return x;
}
int update(int L , int R , int root , int idx , int val )
{
if( L > idx || R < idx )
return root;
++gc;
if( L == idx && R == idx )
{
tree[gc] = Node(-1 ,-1 , (1LL*tree[root].cnt*val)%mod );
return gc;
}
int x = gc;
tree[x] = Node( update(L,mid(L,R),tree[root].L,idx,val), update(mid(L,R)+1,R,tree[root].R,idx,val),(1LL*tree[root].cnt*val)%mod );
return x;
}
long long int query(int L , int R , int root , int qe , int qr )
{
if(qr<L || qe>R)return 1;
if(qe <=L && R <= qr) {
//cout << "Hi " << L << " " << R << " " << tree[ root ].cnt << endl ;
return tree[root].cnt;
}
return ( 1LL*query(L,mid(L,R),tree[root].L,qe,qr) * query(mid(L,R)+1,R,tree[root].R,qe,qr))%mod;
}
long long int primepower[ 32 ][333 ];
int solve( int x , int y )
{
int ans =0 ;
while ( x%y == 0 ) {
x /= y ;
ans++ ;
}
return ans;
}
int twopower[ 25 ] , log_arr[ N ];
int main()
{
twopower[ 0 ] = 1 ;
for( int i = 1 ; i < 25 ; i++ ) twopower[ i ] = 2*twopower[ i - 1 ];
for( int i = 1 ; i < N ; i++ ) {
log_arr[i] = floor(log2(i));
}
int n , q;
for( int i = 2 ; i*i < N ; i++ ) {
if( isprime[i] == 0 )
for( int j = 2*i ; j < N ; j+= i )
isprime[ j ] = 1;
}
for( int i = 1 ; i < N ; i++ )
number[ i ] = 1 ;
for( int i = 334 ; i < N ; i++ )
if( isprime[ i ] == 0 )
for( int j = i ; j < N ; j += i )
number[ j ] = i ;
int counter = 0 ;
for( int i = 2 ; i <= 333 ; i++ )
if( isprime[ i ] == 0 )
primes[ counter++ ] = i ;
scanf("%d%d", &n , &q );
for( int i = 1 ; i <= n ; i++ ) scanf("%d", &arr[i] );
for( int i = 0 ; i < counter ; i++ )
{
//cout << i << " " << endl ;
for (int j = 1 ; j <= n ; j ++)
segtree[ i ][ 0 ][ j ] = (char)(solve( arr[ j ] , primes[ i ] ));
for (int j = 1; 1 << j <= n; j++)
for (int k = 1 ; k + (1 << j) - 1 <= n ; k++ )
if ( segtree[ i ][j - 1][ k ] >= segtree[ i ][j - 1][k + (1 << (j - 1))] )
segtree[ i ][ j ][ k ] = segtree[ i ][ j - 1 ][ k ];
else
segtree[ i ][ j ][ k ] = segtree[ i ][j - 1][k + (1 << (j - 1))];
}
for( int i = 1 ; i <= n ; i++ ) {
arr[ i ] = number[ arr[ i ] ] - 1 ;
if( arr[ i ] == 0 )
arr[ i ] = 1 ;
}
memset(G,-1,sizeof(G));
root[0] = build( 1 , n );
for( int i = 1 ; i <= n ; ++i )
{
int p = root[ i - 1 ];
if( G[ arr[i] ] != -1 )
p = update( 1, n, p, G[arr[i]], power( arr[ i ] , mod - 2 ) );
root[i] = update(1 , n, p, i, arr[ i ] );
G[arr[i]] = i;
}
long long a , b , c , d ;
cin >> a >> b >> c >> d ;
for( int i = 0 ; i < counter ; i++ ) {
long long phi = primes[ i ] - 1 , mul = phi ;
primepower[ 0 ][ i ] = 1 ;
//cout
for( int j = 1 ; j < 32 && phi < N ; j++ , phi *= mul )
primepower[ j ][ i ] = phi ;
}
//cout <<" COunter is " << counter << endl ;
long long ans = 0 ;
for( int j = 1 ; j <= q ; j++ )
{
long long l , r ;
l = 1 + ( a*ans + j*b)%n ;
r = l + ( c*ans + j*d )%(n-l+1);
ans = 1 ;
for( int i = 0 ; i < counter ; i++ )
{
int k = log_arr[r - l + 1];
//cout << k << " " << i << endl ;
int mul = max( segtree[ i ][ k ][ l ]-'\0' , segtree[ i ][ k ][ r - twopower[ k ]+ 1 ]-'\0' );
ans = ( ans * primepower[ mul ][ i ])%mod ;
}
ans = ( ans * query( 1 , n , root[r] , l , r ) )%mod ;
printf("%lld\n",ans );
}
return 0 ;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RkaW8uaD4KI2luY2x1ZGUgPG1hdGguaD4KI2luY2x1ZGUgPG1hcD4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPHN0cmluZy5oPgojaW5jbHVkZSA8c3RkbGliLmg+CiNpbmNsdWRlIDxzZXQ+CiNkZWZpbmUgbW9kIDEwMDAwMDAwMDcKI2RlZmluZSBsbCBsb25nIGxvbmcKI2RlZmluZSBwYiBwdXNoX2JhY2sKI2RlZmluZSBtcCBtYWtlX3BhaXIKI2luY2x1ZGUgPHF1ZXVlPgogCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiAKbG9uZyBsb25nIGdjZCggbG9uZyBsb25nIGEgLCBsb25nIGxvbmcgYiApCnsKICAgIHJldHVybiBiID09IDAgPyBhIDogZ2NkKCBiICwgYSViICk7Cn0KIApsb25nIGxvbmcgcG93ZXIoIGxvbmcgbG9uZyBhICwgbG9uZyBsb25nIGIgKQp7CiAgICBsb25nIGxvbmcgcmV0ID0gMSA7CiAgICB3aGlsZSggYiApIHsKICAgICAgaWYoIGIlMiA9PSAxICkgcmV0ID0gKCByZXQgKiBhICkgJSBtb2QgOwogICAgICBhID0gKCBhICogYSApICUgbW9kIDsKICAgICAgYiAvPSAyIDsKICAgIH0KICAgIHJldHVybiByZXQgOwp9CiAKI2RlZmluZSBOIDEwMDAxMAppbnQgcHJpbWVzWyAzMzMgXSAsIG51bWJlclsgTiBdOwpib29sIGlzcHJpbWVbIE4gXTsKaW50IGFyclsgTiBdIDsKY2hhciBzZWd0cmVlWyA2NyBdWyAyMSBdWyBOIF07CiAKI2RlZmluZSBtaWQoTCxSKSAoKEwrUikvMikKc3RydWN0IE5vZGV7IGludCBjbnQgLCBMICwgUjsKICAgIE5vZGUoKQogICAgewogICAgICAgIGNudCA9IDEgOwogICAgICAgIEwgPSBSID0gLTE7CiAgICB9CiAgICBOb2RlKCBpbnQgeCxpbnQgeSxpbnQgeikKICAgIHsKICAgICAgICBMID0geDsKICAgICAgICBSID0geTsKICAgICAgICBjbnQgPSB6OwogICAgfQp9dHJlZVs2MDAwMDAxXTsKIAppbnQgR1tOXTsKaW50IHJvb3RbTl0gLCBSTVtOXSAsIEJbTl0gLCBWW05dIDsKaW50IGdjID0gMCA7CiAKaW50IGJ1aWxkKGludCBMICwgaW50IFIpCnsKICAgICsrZ2M7CiAgICBpZiggTCA9PSBSICkKICAgICAgICByZXR1cm4gZ2M7CiAgICBpbnQgeCA9IGdjOwogICAgdHJlZVt4XSA9IE5vZGUoYnVpbGQoTCxtaWQoTCxSKSksYnVpbGQobWlkKEwsUikrMSxSKSwxKTsKICAgIHJldHVybiB4Owp9CiAKIAogaW50IHVwZGF0ZShpbnQgTCAsIGludCBSICwgaW50IHJvb3QgLCBpbnQgaWR4ICwgaW50IHZhbCAgKQp7CiAgICBpZiggTCA+IGlkeCB8fCBSIDwgaWR4ICkKICAgICAgICByZXR1cm4gcm9vdDsKICAgICsrZ2M7CiAKICAgIGlmKCBMID09IGlkeCAmJiBSID09IGlkeCApCiAgICB7CiAgICAgICAgdHJlZVtnY10gPSBOb2RlKC0xICwtM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DI1IDsgaSsrICkgdHdvcG93ZXJbIGkgXSA9IDIqdHdvcG93ZXJbIGkgLSAxIF07CiAKICAgZm9yKCBpbnQgaSA9IDEgOyBpIDwgTiA7IGkrKyApIHsKICAgICBsb2dfYXJyW2ldID0gZmxvb3IobG9nMihpKSk7CiAgIH0KICAgaW50IG4gLCBxOwogCiAgIGZvciggaW50IGkgPSAyIDsgaSppIDwgTiA7IGkrKyAgKSB7CiAgICAgaWYoIGlzcHJpbWVbaV0gPT0gMCApCiAgICAgIGZvciggaW50IGogPSAyKmkgOyBqIDwgTiA7IGorPSBpICkKICAgICAgICBpc3ByaW1lWyBqIF0gPSAxOwogICB9CiAKICAgZm9yKCBpbnQgaSA9IDEgOyBpIDwgTiA7IGkrKyApCiAgICBudW1iZXJbIGkgXSA9IDEgOwogCiAgIGZvciggaW50IGkgPSAzMzQgOyBpIDwgTiA7IGkrKyApCiAgICBpZiggaXNwcmltZVsgaSBdID09IDAgKQogICAgICBmb3IoIGludCBqID0gaSA7IGogPCBOIDsgaiArPSBpICkKICAgICAgICBudW1iZXJbIGogXSA9IGkgOwogCiAgIGludCBjb3VudGVyID0gMCA7CiAKICAgZm9yKCBpbnQgaSA9IDIgOyBpIDw9IDMzMyA7IGkrKyApCiAgICBpZiggaXNwcmltZVsgaSBdID09IDAgKQogICAgICBwcmltZXNbIGNvdW50ZXIrKyBdID0gaSA7CiAKIAogICBzY2FuZigiJWQlZCIsICZuICwgJnEgKTsKIAogICBmb3IoIGludCBpID0gMSA7IGkgPD0gbiA7IGkrKyApIHNjYW5mKCIlZCIsICZhcnJbaV0gKTsKIAogICBmb3IoIGludCBpID0gMCA7IGkgPCBjb3VudGVyIDsgaSsrICkKICAgewogICAgIC8vY291dCA8PCBpIDw8ICIgIiAgPDwgZW5kbCA7CiAgICAgZm9yIChpbnQgaiA9IDEgOyBqIDw9IG4gOyBqICsrKQogICAgICAgICBzZWd0cmVlWyBpIF1bIDAgXVsgaiBdID0gKGNoYXIpKHNvbHZlKCBhcnJbIGogXSAsIHByaW1lc1sgaSBdICkpOwogCiAgICAgZm9yIChpbnQgaiA9IDE7IDEgPDwgaiA8PSBuOyBqKyspCiAgICAgICAgIGZvciAoaW50IGsgPSAxIDsgayArICgxIDw8IGopIC0gMSA8PSBuIDsgaysrICkKICAgICAgICAgICAgaWYgKCBzZWd0cmVlWyBpIF1baiAtIDFdWyBrIF0gPj0gc2VndHJlZVsgaSBdW2ogLSAxXVtrICsgKDEgPDwgKGogLSAxKSldICkKICAgICAgICAgICAgICBzZWd0cmVlWyBpIF1bIGogXVsgayBdID0gc2VndHJlZVsgaSBdWyBqIC0gMSBdWyBrIF07CiAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgICBzZWd0cmVlWyBpIF1bIGogXVsgayBdID0gc2VndHJlZVsgaSBdW2ogLSAxXVtrICsgKDEgPDwgKGogLSAxKSldOwogICB9CiAKICAgZm9yKCBpbnQgaSA9IDEgOyBpIDw9IG4gOyBpKysgKSB7CiAgICBhcnJbIGkgXSA9IG51bWJlclsgYXJyWyBpIF0gXSAtIDEgOwogCiAgICBpZiggYXJyWyBpIF0gPT0gMCApCiAgICAgIGFyclsgaSBdID0gMSA7CiAgfQogCiAgIG1lbXNldChHLC0xLHNpemVvZihHKSk7CiAgIHJvb3RbMF0gPSBidWlsZCggMSAsIG4gKTsKICAgZm9yKCBpbnQgaSA9IDEgOyBpIDw9IG4gOyArK2kgKQogICB7CiAgICAgICAgaW50IHAgPSByb290WyBpIC0gMSBdOwogICAgICAgIGlmKCBHWyBhcnJbaV0gXSAhPSAtMSApCiAgICAgICAgICAgIHAgPSB1cGRhdGUoIDEsIG4sIHAsIEdbYXJyW2ldXSwgcG93ZXIoIGFyclsgaSBdICwgbW9kIC0gMiApICk7CiAgICAgICAgcm9vdFtpXSA9IHVwZGF0ZSgxICwgbiwgcCwgaSwgYXJyWyBpIF0gKTsKICAgICAgICBHW2FycltpXV0gPSBpOwogICB9CiAKICAgbG9uZyBsb25nIGEgLCBiICwgYyAsIGQgOwogICBjaW4gPj4gYSA+PiBiID4+IGMgPj4gZCA7CiAKICAgZm9yKCBpbnQgaSA9IDAgOyBpIDwgY291bnRlciA7IGkrKyApIHsKICAgICBsb25nIGxvbmcgcGhpID0gcHJpbWVzWyBpIF0gLSAxICwgbXVsID0gcGhpIDsKICAgICBwcmltZXBvd2VyWyAwIF1bIGkgXSA9IDEgOwogICAgIC8vY291dAogICAgIGZvciggaW50IGogPSAxIDsgaiA8IDMyICYmIHBoaSA8IE4gOyBqKysgLCBwaGkgKj0gbXVsICkKICAgICAgcHJpbWVwb3dlclsgaiBdWyBpIF0gPSBwaGkgOwogICB9CiAgIC8vY291dCA8PCIgQ091bnRlciBpcyAiIDw8IGNvdW50ZXIgPDwgZW5kbCA7CiAKICAgbG9uZyBsb25nIGFucyA9IDAgOwogICBmb3IoIGludCBqID0gMSA7IGogPD0gcSA7IGorKyApCiAgIHsKICAgICAgbG9uZyBsb25nIGwgLCByIDsKICAgICAgbCA9IDEgKyAoIGEqYW5zICsgaipiKSVuIDsKICAgICAgciA9IGwgKyAoIGMqYW5zICsgaipkICklKG4tbCsxKTsKIAogCiAgICAgIGFucyA9IDEgOwogCiAgICAgIGZvciggaW50IGkgPSAwIDsgaSA8IGNvdW50ZXIgOyBpKysgKQogICAgICB7CiAKICAgICAgICBpbnQgayA9IGxvZ19hcnJbciAtIGwgKyAxXTsKICAgICAgICAvL2NvdXQgPDwgayA8PCAiICAiIDw8IGkgPDwgZW5kbCA7CiAgICAgICAgaW50IG11bCA9IG1heCggc2VndHJlZVsgaSBdWyBrIF1bIGwgXS0nXDAnICwgc2VndHJlZVsgaSBdWyBrIF1bIHIgLSB0d29wb3dlclsgayBdKyAxIF0tJ1wwJyApOwogICAgICAgIGFucyA9ICggYW5zICogcHJpbWVwb3dlclsgbXVsIF1bIGkgXSklbW9kIDsKICAgICAgfQogCiAgICAgIGFucyA9ICggYW5zICogcXVlcnkoIDEgLCBuICwgcm9vdFtyXSAsIGwgLCByICkgKSVtb2QgOwogICAgICBwcmludGYoIiVsbGRcbiIsYW5zICk7CiAgIH0KIAogCiAgIHJldHVybiAwIDsKfQ==