#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")

////////////////////////////////////////////////////////////////////////////////
template <unsigned M_> struct ModInt {
  static constexpr unsigned M = M_;
  unsigned x;
  constexpr ModInt() : x(0U) {}
  constexpr ModInt(unsigned x_) : x(x_ % M) {}
  constexpr ModInt(unsigned long long x_) : x(x_ % M) {}
  constexpr ModInt(int x_) : x(((x_ %= static_cast<int>(M)) < 0) ? (x_ + static_cast<int>(M)) : x_) {}
  constexpr ModInt(long long x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
  ModInt &operator+=(const ModInt &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
  ModInt &operator-=(const ModInt &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
  ModInt &operator*=(const ModInt &a) { x = (static_cast<unsigned long long>(x) * a.x) % M; return *this; }
  ModInt &operator/=(const ModInt &a) { return (*this *= a.inv()); }
  ModInt pow(long long e) const {
    if (e < 0) return inv().pow(-e);
    ModInt a = *this, b = 1U; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b;
  }
  ModInt inv() const {
    unsigned a = M, b = x; int y = 0, z = 1;
    for (; b; ) { const unsigned q = a / b; const unsigned c = a - q * b; a = b; b = c; const int w = y - static_cast<int>(q) * z; y = z; z = w; }
    assert(a == 1U); return ModInt(y);
  }
  ModInt operator+() const { return *this; }
  ModInt operator-() const { ModInt a; a.x = x ? (M - x) : 0U; return a; }
  ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); }
  ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); }
  ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); }
  ModInt operator/(const ModInt &a) const { return (ModInt(*this) /= a); }
  template <class T> friend ModInt operator+(T a, const ModInt &b) { return (ModInt(a) += b); }
  template <class T> friend ModInt operator-(T a, const ModInt &b) { return (ModInt(a) -= b); }
  template <class T> friend ModInt operator*(T a, const ModInt &b) { return (ModInt(a) *= b); }
  template <class T> friend ModInt operator/(T a, const ModInt &b) { return (ModInt(a) /= b); }
  explicit operator bool() const { return x; }
  bool operator==(const ModInt &a) const { return (x == a.x); }
  bool operator!=(const ModInt &a) const { return (x != a.x); }
  friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x; }
};
////////////////////////////////////////////////////////////////////////////////

constexpr unsigned MO = 998244353;
using Mint = ModInt<MO>;


constexpr int M = 200'010;
vector<int> lpf;

int N, Q;
vector<int> A;

Mint whole[450][200'010];

int main() {
  lpf.assign(M + 1, 0);
  for (int p = 2; p <= M; ++p) lpf[p] = p;
  for (int p = 2; p <= M; ++p) if (lpf[p] == p) {
    for (int n = p; n <= M; n += p) chmin(lpf[n], p);
  }
  
  for (; ~scanf("%d", &N); ) {
    A.resize(N);
    for (int i = 0; i < N; ++i) {
      scanf("%d", &A[i]);
    }
    scanf("%d", &Q);
    
    vector<vector<pair<int, int>>> B(N);
    for (int i = 0; i < N; ++i) {
      for (int a = A[i]; a > 1; ) {
        const int p = lpf[a];
        int e = 0;
        do { ++e; a /= p; } while (a % p == 0);
        B[i].emplace_back(p, e);
      }
    }
// cerr<<"B = "<<B<<endl;
    
    const int Y = max<int>(N / sqrt(Q), 1);
    const int X = (N + Y - 1) / Y;
// cerr<<"X = "<<X<<", Y = "<<Y<<endl;
    for (int x = 0; x < X; ++x) {
      vector<int> es(M + 1, 0);
      whole[x][x * Y] = 1;
      for (int i = x * Y; i < N; ++i) {
        int prod = 1;
        for (const auto &pe : B[i]) {
          const int p = pe.first;
          const int e = pe.second;
          for (; es[p] < e; ++es[p]) prod *= p;
        }
        whole[x][i + 1] = whole[x][i] * prod;
      }
// cerr<<"whole["<<x<<"] = ";pv(whole[x],whole[x]+(N+1));
    }
    
    vector<vector<pair<int, int>>> nxt(N);
    {
      vector<int> app(M + 1, N);
      for (int i = N; --i >= 0; ) {
        for (const auto &pe : B[i]) {
          const int p = pe.first;
          const int e = pe.second;
          int q = 1;
          for (int f = 1; f <= e; ++f) {
            q *= p;
            nxt[i].emplace_back(p, app[q]);
            app[q] = i;
          }
        }
      }
    }
// cerr<<"nxt = "<<nxt<<endl;
    
    Mint lastans = 1;
    for (int q = 0; q < Q; ++q) {
      int L, R;
      scanf("%d%d", &L, &R);
      L = (int)(L * lastans).x % N + 1;
      R = (int)(R * lastans).x % N + 1;
      if (L > R) swap(L, R);
      --L;
// cerr<<COLOR("93")<<L<<" "<<R<<COLOR()<<endl;
      
      const int k = (L + Y - 1) / Y;
      int l = k * Y;
      Mint ans = 1;
      if (l <= R) {
        ans = whole[k][R];
      } else {
        l = R;
      }
      for (; --l >= L; ) {
        int prod = 1;
        for (const auto &qi : nxt[l]) {
          if (qi.second >= R) prod *= qi.first;
        }
        ans *= prod;
      }
      printf("%u\n", ans.x);
      lastans = ans;
    }
  }
  return 0;
}