#include using namespace std; typedef signed long long ll; #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define FORR2(x,y,arr) for(auto& [x,y]:arr) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) template bool chmax(T &a, const T &b) { if(a bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;} //------------------------------------------------------- const int B=202020; const int DI=100; vector D[B]; int FD[202020]; ll dp[B/DI][B/DI]; vector pos[B]; const ll mo=998244353; int N,Q; int A[B]; vector> pre[B],nex[B]; void solve() { int i,j,k,l,r,x,y; string s; for(i=2;i<=200000;i++) if(D[i].empty()) { for(j=i;j<=200000;j+=i) { FD[j]=i; x=j; while(x%i==0) x/=i; D[j].push_back(j/x); } } FOR(i,B) pos[i].push_back(0); cin>>N; FOR(i,B) A[i]=1; for(i=1;i<=N;i++) { cin>>A[i]; FORR(d,D[A[i]]) { x=FD[d]; y=d; while(y>1) { nex[pos[y].back()].push_back({y,i}); pre[i].push_back({y,pos[y].back()}); pos[y].push_back(i); y/=x; } } } FOR(i,B) if(pos[i].back()!=0) nex[pos[i].back()].push_back({i,N+1}); FOR(x,B/DI) { ll ret=1; for(y=x*DI;y>Q; ll ret=1; while(Q--) { ll qa,qb; cin>>qa>>qb; x=(qa*ret%mo)%N+1; y=(qb*ret%mo)%N+1; if(x>y) swap(x,y); y++; ret=1; if(y-x<=2*DI) { ret=A[x]; for(i=x+1;i=R) ret=ret*FD[a]%mo; } while(R