#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <cassert>

#include <iostream>

#include <vector>
#include <queue>
#include <list>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <algorithm>
#include <utility>
#include <memory>
#include <bitset>
#include <string>
#include <tuple>
#include <functional>
using namespace std;

#define lowbit(x) ((x) & -(x))
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(l,r) ((l)+(((r)-(l))>>1))
#define fi first
#define se second
#define mk make_pair
#define mt make_tuple
#define pb push_back
#define epb emplace_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

using LL = long long;
using ULL = unsigned long long;
//using LL = __int64;
//using ULL = unsigned __int64;
using pii = pair<int, int>;
using pdd = pair<double, double>;
using pLL = pair<LL, LL>;

const int INF = 0x3f3f3f3f;
const LL LINF = 0x3f3f3f3f3f3f3f3f;
const double DINF = 1e100;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int e5 = 100000; // 1e5
const int e6 = 1000000; //1e6;
const int MOD_1e9 = 1000000007; //1e9 + 7
const int MOD_998 = 998244353;
const int MOD = MOD_998;

template< typename T > inline void get_min(T &x, T y) {if(y < x) x = y;}
template< typename T > inline void get_max(T &x, T y) {if(x < y) x = y;}
template< typename T > inline T get_abs(T x) {if(x < 0) return -x; return x;}
template< typename T > inline void get_unique(vector<T> &vec) {sort(all(vec)); vec.erase(unique(all(vec)), vec.end());}

inline int sig(double x) {return x < -eps ? -1 : eps < x;}
LL fp(LL a, LL n, LL mod = MOD)
{
    if(n < 0) a = fp(a, mod - 2, mod), n = -n;
    LL res = 1;
    for(; n; n >>= 1, a = a * a % mod) if(n & 1) res = res * a % mod;
    return res;
}

template< int mod > class Mint
{
public:
    int x;
    Mint():x(0) {}
    Mint(int _x): x(_x) {if(x < 0 || x >= mod) x %= mod; if(x < 0) x += mod;}
    Mint(LL _x) {if(_x < 0 || _x >= mod) _x %= mod; if(_x < 0) _x += mod; x = _x;}
    Mint operator - () const {return Mint(x == 0 ? x : mod - x);}
    Mint operator + (const Mint &rhs) const {return Mint(x + rhs.x >= mod ? x + rhs.x - mod : x + rhs.x);}
    Mint operator - (const Mint &rhs) const {return Mint(x - rhs.x < 0 ? x - rhs.x + mod : x - rhs.x);}
    Mint operator * (const Mint &rhs) const {return Mint((LL)x * rhs.x % mod);}
    Mint operator / (const Mint &rhs) const {return Mint((LL)x * fp(rhs.x, -1, mod) % mod);}
    bool operator == (const Mint &rhs) const {return x == rhs.x;}
    bool operator != (const Mint &rhs) const {return x != rhs.x;}
    Mint &operator += (const Mint &rhs) {x += rhs.x; if(x >= mod) x -= mod; return *this;}
    Mint &operator -= (const Mint &rhs) {x -= rhs.x; if(x < 0) x += mod; return *this;}
    Mint &operator *= (const Mint &rhs) {x = (LL)x * rhs.x % mod; return *this;}
    Mint &operator /= (const Mint &rhs) {x = (LL)x * fp(rhs.x, -1, mod) % mod; return *this;}
    friend ostream &operator << (ostream &out, const Mint &rhs) {return out << to_string(rhs.x);}
    Mint inv() const {return Mint(fp(x, -1, mod));}
    Mint pow(int k) const {return Mint(fp(x, k, mod));}
};

class fast_reader
{
private:
    int buff_size;
    char *buff_ptr;
    char *ptr;
    char *tail;
    bool is_open;
    fast_reader(const fast_reader &) = delete;
    fast_reader &operator = (const fast_reader &) = delete;

    inline bool is_digit() const {return '0' <= *ptr && *ptr <= '9';}
    inline bool is_blank() const {return *ptr == ' ' || *ptr == '\n' || *ptr == '\t' || *ptr == '\0';}
    template <typename T> inline void read_i(T &x)
    {
        bool f = false;
        x = 0;
        while(ptr < tail && !is_digit()) {if(*ptr == '-') f = true; ptr++;}
        while(ptr < tail && is_digit()) {x = (x << 1) + (x << 3) + (*ptr & 0xf); ptr++;}
        if(f) x = -x;
    }
    template <typename T> inline void read_f(T &x)
    {
        static char t_buff[1 << 6];
        read(t_buff);
        x = atof(t_buff);
    }
public:
    fast_reader(): buff_size(0), buff_ptr(nullptr), ptr(nullptr), tail(nullptr), is_open(false) {}
    ~fast_reader() {if(is_open) free(buff_ptr);}
    template <typename T> fast_reader &operator >> (T &x) {read(x); return *this;}
    template<typename T, typename ...Args> inline void read(T &x, Args &...args) {read(x); read(args...);}
    inline bool is_end() {while(ptr < tail && is_blank()) ptr++; return ptr >= tail;}

    inline void open_alter(int _base_size = 1 << 24) //2^24B = 16MB
    {
        if(is_open) throw runtime_error("fast reader is reopened!");

        int input_size = 0;
        int call_size = _base_size;
        buff_ptr = (char *) malloc(call_size);
        input_size += fread(buff_ptr, 1, call_size, stdin);
        while(feof(stdin) == 0)
        {
            int recall_size = call_size;
            buff_ptr = (char *) realloc(buff_ptr, call_size + recall_size);
            tail = buff_ptr + call_size;
            input_size += fread(tail, 1, recall_size, stdin);
            call_size += recall_size;
        }
        buff_ptr = (char *) realloc(buff_ptr, input_size);
        ptr = buff_ptr;
        tail = buff_ptr + input_size;
        buff_size = input_size;
        is_open = true;
    }

    inline void read(int &x) {read_i(x);}
    inline void read(unsigned int &x) {read_i(x);}
    inline void read(long long &x) {read_i(x);}
    inline void read(unsigned long long &x) {read_i(x);}
    inline void read(float &x) {read_f(x);}
    inline void read(double &x) {read_f(x);}
    inline void read(char *str)
    {
        while(ptr < tail && is_blank()) ptr++;
        while(ptr < tail && !is_blank()) *str = *ptr++, str++;
        *str = '\0';
    }
    inline void read(string &s)
    {
        while(ptr < tail && is_blank()) ptr++;
        char *pre = ptr;
        while(ptr < tail && !is_blank()) ptr++;
        s = std::move(string(pre, ptr)); //<utility>
    }
}reader;

const int maxn = (int) 1e5 + 5;
const int maxm = (int) 2e5 + 5;

using mint = Mint<MOD_1e9>;

struct Node
{
    mint x;
    int lch, rch;
}T[maxn * 300];
int tcnt;

int rt[maxn];

void upd(int &o, mint x, int p, int l, int r, int id)
{
    int oo = ++tcnt;
    T[oo] = T[o];
    o = oo;

    if(l == r)
    {
        T[o].x *= x;
        return ;
    }
    int mid = MID(l, r);
    if(p <= mid) upd(T[o].lch, x, p, lson);
    else upd(T[o].rch, x, p, rson);
    T[o].x = T[T[o].lch].x * T[T[o].rch].x;
}

mint que(int o, int L, int R, int l, int r, int id)
{
    if(L <= l && r <= R) return T[o].x;
    int mid = MID(l, r);
    if(R <= mid) return que(T[o].lch, L, R, lson);
    if(mid < L) return que(T[o].rch, L, R, rson);
    return que(T[o].lch, L, R, lson) * que(T[o].rch, L, R, rson);
}

int n;
int a[maxn];
int primes[maxm], low_prime[maxm];
mint po[20][maxm], inv[20][maxm];

struct item{int a, b, c;};
stack<item> stk[maxn];

void work()
{
    reader >>n;
    int mx = 0;
    for(int i = 1; i <= n; i++)
    {
        reader >>a[i];
        get_max(mx, a[i]);
    }

    {
        int m = 0;
        for(int i = 2; i <= mx; i++)
        {
            if(low_prime[i] == 0)
            {
                primes[m++] = i;
                low_prime[i] = i;

                po[0][i] = 1;
                for(int j = 1; j < 20; j++) po[j][i] = po[j - 1][i] * i;
                inv[19][i] = po[19][i].inv();
                for(int j = 18; ~j; j--) inv[j][i] = inv[j + 1][i] * i;
            }

            for(int j = 0; j < m; j++)
            {
                if(i * primes[j] > mx) break;
                low_prime[i * primes[j]] = primes[j];
                if(i % primes[j] == 0) break;
            }
        }
    }

    tcnt = 0;
    T[0].x = 1;
    T[0].lch = T[0].rch = 0;

    rt[0] = 0;
    for(int i = 1; i <= n; i++)
    {
        int x = a[i];
        rt[i] = rt[i - 1];

        while(x != 1)
        {
            int p = low_prime[x];
            int cnt = 0;
            while(x % p == 0)
            {
                x /= p;
                cnt++;
            }

            while(!stk[p].empty() && stk[p].top().a <= cnt)
            {
                int c = stk[p].top().a, j = stk[p].top().b, r = stk[p].top().c;
                stk[p].pop();
//                upd(rt[i], mint(p).pow(r).inv(), j, 1, n, 1);
                upd(rt[i], inv[r][p], j, 1, n, 1);
            }

            if(!stk[p].empty())
            {
                int c = stk[p].top().a, j = stk[p].top().b, r = stk[p].top().c;
                stk[p].pop();
//                upd(rt[i], mint(p).pow(r).inv(), j, 1, n, 1);
                upd(rt[i], inv[r][p], j, 1, n, 1);
//                upd(rt[i], mint(p).pow(c - cnt), j, 1, n, 1);
                upd(rt[i], po[c - cnt][p], j, 1, n, 1);
                stk[p].emplace(item{c, j, c - cnt});
            }

//            upd(rt[i], mint(p).pow(cnt), i, 1, n, 1);
            upd(rt[i], po[cnt][p], i, 1, n, 1);
            stk[p].emplace(item{cnt, i, cnt});
        }
    }

    int q;
    reader >>q;
    int last = 0;
    while(q--)
    {
        int l, r;
        reader >>l >>r;

        l = (l + last) % n + 1;
        r = (r + last) % n + 1;
        if(l > r) swap(l, r);

        last = que(rt[r], l, r, 1, n, 1).x;
        printf("%d\n", last);
    }
}

int main()
{
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416
    reader.open_alter(1 << 24);

    int tc = 1;
//    reader >> tc;
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
//        printf("Case #%d:\n", ca);
        work();
    }
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <cassert>

#include <iostream>

#include <vector>
#include <queue>
#include <list>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <algorithm>
#include <utility>
#include <memory>
#include <bitset>
#include <string>
#include <tuple>
#include <functional>
using namespace std;

#define lowbit(x) ((x) & -(x))
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(l,r) ((l)+(((r)-(l))>>1))
#define fi first
#define se second
#define mk make_pair
#define mt make_tuple
#define pb push_back
#define epb emplace_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

using LL = long long;
using ULL = unsigned long long;
//using LL = __int64;
//using ULL = unsigned __int64;
using pii = pair<int, int>;
using pdd = pair<double, double>;
using pLL = pair<LL, LL>;

const int INF = 0x3f3f3f3f;
const LL LINF = 0x3f3f3f3f3f3f3f3f;
const double DINF = 1e100;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int e5 = 100000; // 1e5
const int e6 = 1000000; //1e6;
const int MOD_1e9 = 1000000007; //1e9 + 7
const int MOD_998 = 998244353;
const int MOD = MOD_998;

template< typename T > inline void get_min(T &x, T y) {if(y < x) x = y;}
template< typename T > inline void get_max(T &x, T y) {if(x < y) x = y;}
template< typename T > inline T get_abs(T x) {if(x < 0) return -x; return x;}
template< typename T > inline void get_unique(vector<T> &vec) {sort(all(vec)); vec.erase(unique(all(vec)), vec.end());}

inline int sig(double x) {return x < -eps ? -1 : eps < x;}
LL fp(LL a, LL n, LL mod = MOD)
{
    if(n < 0) a = fp(a, mod - 2, mod), n = -n;
    LL res = 1;
    for(; n; n >>= 1, a = a * a % mod) if(n & 1) res = res * a % mod;
    return res;
}

template< int mod > class Mint
{
public:
    int x;
    Mint():x(0) {}
    Mint(int _x): x(_x) {if(x < 0 || x >= mod) x %= mod; if(x < 0) x += mod;}
    Mint(LL _x) {if(_x < 0 || _x >= mod) _x %= mod; if(_x < 0) _x += mod; x = _x;}
    Mint operator - () const {return Mint(x == 0 ? x : mod - x);}
    Mint operator + (const Mint &rhs) const {return Mint(x + rhs.x >= mod ? x + rhs.x - mod : x + rhs.x);}
    Mint operator - (const Mint &rhs) const {return Mint(x - rhs.x < 0 ? x - rhs.x + mod : x - rhs.x);}
    Mint operator * (const Mint &rhs) const {return Mint((LL)x * rhs.x % mod);}
    Mint operator / (const Mint &rhs) const {return Mint((LL)x * fp(rhs.x, -1, mod) % mod);}
    bool operator == (const Mint &rhs) const {return x == rhs.x;}
    bool operator != (const Mint &rhs) const {return x != rhs.x;}
    Mint &operator += (const Mint &rhs) {x += rhs.x; if(x >= mod) x -= mod; return *this;}
    Mint &operator -= (const Mint &rhs) {x -= rhs.x; if(x < 0) x += mod; return *this;}
    Mint &operator *= (const Mint &rhs) {x = (LL)x * rhs.x % mod; return *this;}
    Mint &operator /= (const Mint &rhs) {x = (LL)x * fp(rhs.x, -1, mod) % mod; return *this;}
    friend ostream &operator << (ostream &out, const Mint &rhs) {return out << to_string(rhs.x);}
    Mint inv() const {return Mint(fp(x, -1, mod));}
    Mint pow(int k) const {return Mint(fp(x, k, mod));}
};

class fast_reader
{
private:
    int buff_size;
    char *buff_ptr;
    char *ptr;
    char *tail;
    bool is_open;
    fast_reader(const fast_reader &) = delete;
    fast_reader &operator = (const fast_reader &) = delete;

    inline bool is_digit() const {return '0' <= *ptr && *ptr <= '9';}
    inline bool is_blank() const {return *ptr == ' ' || *ptr == '\n' || *ptr == '\t' || *ptr == '\0';}
    template <typename T> inline void read_i(T &x)
    {
        bool f = false;
        x = 0;
        while(ptr < tail && !is_digit()) {if(*ptr == '-') f = true; ptr++;}
        while(ptr < tail && is_digit()) {x = (x << 1) + (x << 3) + (*ptr & 0xf); ptr++;}
        if(f) x = -x;
    }
    template <typename T> inline void read_f(T &x)
    {
        static char t_buff[1 << 6];
        read(t_buff);
        x = atof(t_buff);
    }
public:
    fast_reader(): buff_size(0), buff_ptr(nullptr), ptr(nullptr), tail(nullptr), is_open(false) {}
    ~fast_reader() {if(is_open) free(buff_ptr);}
    template <typename T> fast_reader &operator >> (T &x) {read(x); return *this;}
    template<typename T, typename ...Args> inline void read(T &x, Args &...args) {read(x); read(args...);}
    inline bool is_end() {while(ptr < tail && is_blank()) ptr++; return ptr >= tail;}

    inline void open_alter(int _base_size = 1 << 24) //2^24B = 16MB
    {
        if(is_open) throw runtime_error("fast reader is reopened!");

        int input_size = 0;
        int call_size = _base_size;
        buff_ptr = (char *) malloc(call_size);
        input_size += fread(buff_ptr, 1, call_size, stdin);
        while(feof(stdin) == 0)
        {
            int recall_size = call_size;
            buff_ptr = (char *) realloc(buff_ptr, call_size + recall_size);
            tail = buff_ptr + call_size;
            input_size += fread(tail, 1, recall_size, stdin);
            call_size += recall_size;
        }
        buff_ptr = (char *) realloc(buff_ptr, input_size);
        ptr = buff_ptr;
        tail = buff_ptr + input_size;
        buff_size = input_size;
        is_open = true;
    }

    inline void read(int &x) {read_i(x);}
    inline void read(unsigned int &x) {read_i(x);}
    inline void read(long long &x) {read_i(x);}
    inline void read(unsigned long long &x) {read_i(x);}
    inline void read(float &x) {read_f(x);}
    inline void read(double &x) {read_f(x);}
    inline void read(char *str)
    {
        while(ptr < tail && is_blank()) ptr++;
        while(ptr < tail && !is_blank()) *str = *ptr++, str++;
        *str = '\0';
    }
    inline void read(string &s)
    {
        while(ptr < tail && is_blank()) ptr++;
        char *pre = ptr;
        while(ptr < tail && !is_blank()) ptr++;
        s = std::move(string(pre, ptr)); //<utility>
    }
}reader;

const int maxn = (int) 1e5 + 5;
const int maxm = (int) 2e5 + 5;

using mint = Mint<MOD_1e9>;

struct Node
{
    mint x;
    int lch, rch;
}T[maxn * 300];
int tcnt;

int rt[maxn];

void upd(int &o, mint x, int p, int l, int r, int id)
{
    int oo = ++tcnt;
    T[oo] = T[o];
    o = oo;

    if(l == r)
    {
        T[o].x *= x;
        return ;
    }
    int mid = MID(l, r);
    if(p <= mid) upd(T[o].lch, x, p, lson);
    else upd(T[o].rch, x, p, rson);
    T[o].x = T[T[o].lch].x * T[T[o].rch].x;
}

mint que(int o, int L, int R, int l, int r, int id)
{
    if(L <= l && r <= R) return T[o].x;
    int mid = MID(l, r);
    if(R <= mid) return que(T[o].lch, L, R, lson);
    if(mid < L) return que(T[o].rch, L, R, rson);
    return que(T[o].lch, L, R, lson) * que(T[o].rch, L, R, rson);
}

int n;
int a[maxn];

int primes[maxm], low_prime[maxm];
mint po[20][maxm], inv[20][maxm];
struct item{int a, b, c;};
stack<item> stk[maxm];

void work()
{
    reader >>n;
    int mx = 0;
    for(int i = 1; i <= n; i++)
    {
        reader >>a[i];
        get_max(mx, a[i]);
    }

    {
        int m = 0;
        for(int i = 2; i <= mx; i++)
        {
            if(low_prime[i] == 0)
            {
                primes[m++] = i;
                low_prime[i] = i;

                po[0][i] = 1;
                for(int j = 1; j < 20; j++) po[j][i] = po[j - 1][i] * i;
                inv[19][i] = po[19][i].inv();
                for(int j = 18; ~j; j--) inv[j][i] = inv[j + 1][i] * i;
            }

            for(int j = 0; j < m; j++)
            {
                if(i * primes[j] > mx) break;
                low_prime[i * primes[j]] = primes[j];
                if(i % primes[j] == 0) break;
            }
        }
    }

    tcnt = 0;
    T[0].x = 1;
    T[0].lch = T[0].rch = 0;

    rt[0] = 0;
    for(int i = 1; i <= n; i++)
    {
        int x = a[i];
        rt[i] = rt[i - 1];

        while(x != 1)
        {
            int p = low_prime[x];
            int cnt = 0;
            while(x % p == 0)
            {
                x /= p;
                cnt++;
            }

            while(!stk[p].empty() && stk[p].top().a <= cnt)
            {
                int c = stk[p].top().a, j = stk[p].top().b, r = stk[p].top().c;
                stk[p].pop();
//                upd(rt[i], mint(p).pow(r).inv(), j, 1, n, 1);
                upd(rt[i], inv[r][p], j, 1, n, 1);
            }

            if(!stk[p].empty())
            {
                int c = stk[p].top().a, j = stk[p].top().b, r = stk[p].top().c;
                stk[p].pop();
////                upd(rt[i], mint(p).pow(r).inv(), j, 1, n, 1);
//                upd(rt[i], inv[r][p], j, 1, n, 1);
////                upd(rt[i], mint(p).pow(c - cnt), j, 1, n, 1);
//                upd(rt[i], po[c - cnt][p], j, 1, n, 1);
                int t = r - (c - cnt);
                if(t > 0) upd(rt[i], inv[t][p], j, 1, n, 1);

                stk[p].emplace(item{c, j, c - cnt});
            }

//            upd(rt[i], mint(p).pow(cnt), i, 1, n, 1);
            upd(rt[i], po[cnt][p], i, 1, n, 1);
            stk[p].emplace(item{cnt, i, cnt});
        }
    }

    int q;
    reader >>q;
    int last = 0;
    while(q--)
    {
        int l, r;
        reader >>l >>r;

        l = (l + last) % n + 1;
        r = (r + last) % n + 1;
        if(l > r) swap(l, r);

        last = que(rt[r], l, r, 1, n, 1).x;
        printf("%d\n", last);
    }
}

int main()
{
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416
    reader.open_alter(1 << 24);

    int tc = 1;
//    reader >> tc;
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
//        printf("Case #%d:\n", ca);
        work();
    }
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <cassert>

#include <iostream>

#include <vector>
#include <queue>
#include <list>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <algorithm>
#include <utility>
#include <memory>
#include <bitset>
#include <string>
#include <tuple>
#include <functional>
using namespace std;

#define lowbit(x) ((x) & -(x))
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(l,r) ((l)+(((r)-(l))>>1))
#define fi first
#define se second
#define mk make_pair
#define mt make_tuple
#define pb push_back
#define epb emplace_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

using LL = long long;
using ULL = unsigned long long;
//using LL = __int64;
//using ULL = unsigned __int64;
using pii = pair<int, int>;
using pdd = pair<double, double>;
using pLL = pair<LL, LL>;

const int INF = 0x3f3f3f3f;
const LL LINF = 0x3f3f3f3f3f3f3f3f;
const double DINF = 1e100;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int e5 = 100000; // 1e5
const int e6 = 1000000; //1e6;
const int MOD_1e9 = 1000000007; //1e9 + 7
const int MOD_998 = 998244353;
const int MOD = MOD_998;

template< typename T > inline void get_min(T &x, T y) {if(y < x) x = y;}
template< typename T > inline void get_max(T &x, T y) {if(x < y) x = y;}
template< typename T > inline T get_abs(T x) {if(x < 0) return -x; return x;}
template< typename T > inline void get_unique(vector<T> &vec) {sort(all(vec)); vec.erase(unique(all(vec)), vec.end());}

inline int sig(double x) {return x < -eps ? -1 : eps < x;}
LL fp(LL a, LL n, LL mod = MOD)
{
    if(n < 0) a = fp(a, mod - 2, mod), n = -n;
    LL res = 1;
    for(; n; n >>= 1, a = a * a % mod) if(n & 1) res = res * a % mod;
    return res;
}

template< int mod > class Mint
{
public:
    int x;
    Mint():x(0) {}
    Mint(int _x): x(_x) {if(x < 0 || x >= mod) x %= mod; if(x < 0) x += mod;}
    Mint(LL _x) {if(_x < 0 || _x >= mod) _x %= mod; if(_x < 0) _x += mod; x = _x;}
    Mint operator - () const {return Mint(x == 0 ? x : mod - x);}
    Mint operator + (const Mint &rhs) const {return Mint(x + rhs.x >= mod ? x + rhs.x - mod : x + rhs.x);}
    Mint operator - (const Mint &rhs) const {return Mint(x - rhs.x < 0 ? x - rhs.x + mod : x - rhs.x);}
    Mint operator * (const Mint &rhs) const {return Mint((LL)x * rhs.x % mod);}
    Mint operator / (const Mint &rhs) const {return Mint((LL)x * fp(rhs.x, -1, mod) % mod);}
    bool operator == (const Mint &rhs) const {return x == rhs.x;}
    bool operator != (const Mint &rhs) const {return x != rhs.x;}
    Mint &operator += (const Mint &rhs) {x += rhs.x; if(x >= mod) x -= mod; return *this;}
    Mint &operator -= (const Mint &rhs) {x -= rhs.x; if(x < 0) x += mod; return *this;}
    Mint &operator *= (const Mint &rhs) {x = (LL)x * rhs.x % mod; return *this;}
    Mint &operator /= (const Mint &rhs) {x = (LL)x * fp(rhs.x, -1, mod) % mod; return *this;}
    friend ostream &operator << (ostream &out, const Mint &rhs) {return out << to_string(rhs.x);}
    Mint inv() const {return Mint(fp(x, -1, mod));}
    Mint pow(int k) const {return Mint(fp(x, k, mod));}
};

class fast_reader
{
private:
    int buff_size;
    char *buff_ptr;
    char *ptr;
    char *tail;
    bool is_open;
    fast_reader(const fast_reader &) = delete;
    fast_reader &operator = (const fast_reader &) = delete;

    inline bool is_digit() const {return '0' <= *ptr && *ptr <= '9';}
    inline bool is_blank() const {return *ptr == ' ' || *ptr == '\n' || *ptr == '\t' || *ptr == '\0';}
    template <typename T> inline void read_i(T &x)
    {
        bool f = false;
        x = 0;
        while(ptr < tail && !is_digit()) {if(*ptr == '-') f = true; ptr++;}
        while(ptr < tail && is_digit()) {x = (x << 1) + (x << 3) + (*ptr & 0xf); ptr++;}
        if(f) x = -x;
    }
    template <typename T> inline void read_f(T &x)
    {
        static char t_buff[1 << 6];
        read(t_buff);
        x = atof(t_buff);
    }
public:
    fast_reader(): buff_size(0), buff_ptr(nullptr), ptr(nullptr), tail(nullptr), is_open(false) {}
    ~fast_reader() {if(is_open) free(buff_ptr);}
    template <typename T> fast_reader &operator >> (T &x) {read(x); return *this;}
    template<typename T, typename ...Args> inline void read(T &x, Args &...args) {read(x); read(args...);}
    inline bool is_end() {while(ptr < tail && is_blank()) ptr++; return ptr >= tail;}

    inline void open_alter(int _base_size = 1 << 24) //2^24B = 16MB
    {
        if(is_open) throw runtime_error("fast reader is reopened!");

        int input_size = 0;
        int call_size = _base_size;
        buff_ptr = (char *) malloc(call_size);
        input_size += fread(buff_ptr, 1, call_size, stdin);
        while(feof(stdin) == 0)
        {
            int recall_size = call_size;
            buff_ptr = (char *) realloc(buff_ptr, call_size + recall_size);
            tail = buff_ptr + call_size;
            input_size += fread(tail, 1, recall_size, stdin);
            call_size += recall_size;
        }
        buff_ptr = (char *) realloc(buff_ptr, input_size);
        ptr = buff_ptr;
        tail = buff_ptr + input_size;
        buff_size = input_size;
        is_open = true;
    }

    inline void read(int &x) {read_i(x);}
    inline void read(unsigned int &x) {read_i(x);}
    inline void read(long long &x) {read_i(x);}
    inline void read(unsigned long long &x) {read_i(x);}
    inline void read(float &x) {read_f(x);}
    inline void read(double &x) {read_f(x);}
    inline void read(char *str)
    {
        while(ptr < tail && is_blank()) ptr++;
        while(ptr < tail && !is_blank()) *str = *ptr++, str++;
        *str = '\0';
    }
    inline void read(string &s)
    {
        while(ptr < tail && is_blank()) ptr++;
        char *pre = ptr;
        while(ptr < tail && !is_blank()) ptr++;
        s = std::move(string(pre, ptr)); //<utility>
    }
}reader;

const int maxn = (int) 1e5 + 5;
const int maxm = (int) 2e5 + 5;

using mint = Mint<MOD_1e9>;

struct Node
{
    mint x;
    int lch, rch;
}T[maxn * 300];
int tcnt;

int rt[maxn];

void upd(int &o, mint x, int p, int l, int r, int id)
{
    int oo = ++tcnt;
    T[oo] = T[o];
    o = oo;

    if(l == r)
    {
        T[o].x *= x;
        return ;
    }
    int mid = MID(l, r);
    if(p <= mid) upd(T[o].lch, x, p, lson);
    else upd(T[o].rch, x, p, rson);
    T[o].x = T[T[o].lch].x * T[T[o].rch].x;
}

mint que(int o, int L, int R, int l, int r, int id)
{
    if(L <= l && r <= R) return T[o].x;
    int mid = MID(l, r);
    if(R <= mid) return que(T[o].lch, L, R, lson);
    if(mid < L) return que(T[o].rch, L, R, rson);
    return que(T[o].lch, L, R, lson) * que(T[o].rch, L, R, rson);
}

int n;
int a[maxn];
int primes[maxm], low_prime[maxm];
mint po[20][maxm], inv[20][maxm];
stack<tuple<int, int, int>> stk[maxn];

void work()
{
    reader >>n;
    for(int i = 1; i <= n; i++) reader >>a[i];

    int mx = 0;
    for(int i = 1; i <= n; i++) get_max(mx, a[i]);

    {
        for(int i = 0; i <= mx; i++) low_prime[i] = 0;

        int m = 0;
        for(int i = 2; i <= mx; i++)
        {
            if(low_prime[i] == 0)
            {
                primes[m++] = i;
                low_prime[i] = i;

                po[0][i] = 1;
                for(int j = 1; j < 20; j++) po[j][i] = po[j - 1][i] * i;
                inv[19][i] = po[19][i].inv();
                for(int j = 18; ~j; j--) inv[j][i] = inv[j + 1][i] * i;
            }

            for(int j = 0; j < m; j++)
            {
                if(i * primes[j] > mx) break;
                low_prime[i * primes[j]] = primes[j];
                if(i % primes[j] == 0) break;
            }
        }
    }

    for(int i = 0; i <= mx; i++)
        while(!stk[i].empty())
            stk[i].pop();
    tcnt = 0;
    T[0].x = 1;
    T[0].lch = T[0].rch = 0;

    rt[0] = 0;
    for(int i = 1; i <= n; i++)
    {
        int x = a[i];
        rt[i] = rt[i - 1];

        while(x != 1)
        {
            int p = low_prime[x];
            int cnt = 0;
            while(x % p == 0)
            {
                x /= p;
                cnt++;
            }

            while(!stk[p].empty() && get<0>(stk[p].top()) <= cnt)
            {
                auto [c, j, r] = stk[p].top();
                stk[p].pop();
//                upd(rt[i], mint(p).pow(r).inv(), j, 1, n, 1);
                upd(rt[i], inv[r][p], j, 1, n, 1);
            }

            if(!stk[p].empty())
            {
                auto [c, j, r] = stk[p].top();
                stk[p].pop();
//                upd(rt[i], mint(p).pow(r).inv(), j, 1, n, 1);
                upd(rt[i], inv[r][p], j, 1, n, 1);
//                upd(rt[i], mint(p).pow(c - cnt), j, 1, n, 1);
                upd(rt[i], po[c - cnt][p], j, 1, n, 1);
                stk[p].emplace(tuple<int, int, int> {c, j, c - cnt});
            }

//            upd(rt[i], mint(p).pow(cnt), i, 1, n, 1);
            upd(rt[i], po[cnt][p], i, 1, n, 1);
            stk[p].emplace(tuple<int, int, int> {cnt, i, cnt});
        }
    }

    int q;
    reader >>q;
    int last = 0;
    while(q--)
    {
        int l, r;
        reader >>l >>r;

        l = (l + last) % n + 1;
        r = (r + last) % n + 1;
        if(l > r) swap(l, r);

        last = que(rt[r], l, r, 1, n, 1).x;
        printf("%d\n", last);
    }
}

int main()
{
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416
    reader.open_alter(1 << 24);

    int tc = 1;
//    reader >> tc;
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
//        printf("Case #%d:\n", ca);
        work();
    }
    return 0;
}


#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#include <atcoder/all>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
//using namespace atcoder;

typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 103020;
const int K = 300;
const int KK = 18;
const int mod = 1e9 + 7;
const int M = 90;
short st[90][N][20];
int g[N], b[N + N];
int a[90][N];
bitset <20000> bl[400];
int binpow(int x, int y){
    int res = 1;
    while(y){
        if (y % 2) res = res * x % mod;
        y /= 2;
        x = x * x % mod;
    }
    return res;
}
int query(int k, int L, int R){
    int j = g[R - L + 1];
    int minimum = max(st[k][L][j], st[k][R - (1 << j) + 1][j]);
    return minimum;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    vector <int> p;
    map <int,int> f;
    for (int i = 2; i <= 2e5; i++){
        if (b[i] == 0){
            p.pb(i);
            f[i] = p.size() - 1;
            for (int j = i; j <= 2e5; j += i){
                b[j] = 1;
            }
        }
    }
    for (int i = 1; i <= 2e5; i++) b[i] = 0;
    g[1] = 0;
    for (int i = 2; i < N; i++)
        g[i] = g[i/2] + 1;
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++){
        int x;
        cin >> x;
        for (int j = 0; j < M; j++){
            int y = 0;
            while(x % p[j] == 0){
                y++;
                x /= p[j];
            }
            a[j][i] = y;
        }
        if (x != 1){
            b[i] = f[x];
        }
    }
    for (int k = 0; k < M; k++){
        for (int i = 0; i < N; i++)
            st[k][i][0] = a[k][i];
        for (int j = 1; j <= KK; j++)
            for (int i = 0; i + (1 << j) < N; i++)
                st[k][i][j] = max(st[k][i][j-1], st[k][i + (1 << (j - 1))][j - 1]);
    }
    int q;
    cin >> q;
    int last = 0;
    for (int i = 1; i < n; i += K){
        for (int j = 1; j < i + K; j++){
            if (b[j] != 0) bl[i / K][b[j]] = 1;
        }
    }
    while(q--){
        int x, y, l, r;
        cin >> x >> y;
        l = (last + x) % n + 1;
        r = (last + y) % n + 1;
        if (l > r) swap(l, r);
        int ans = 1;
        for (int i = 0; i < M; i++){
            int z = query(i, l, r);
            ans = ans * binpow(p[i], z) % mod;
        }
        bitset <20000> bs;
        while(l <= r && l % K != 1){
            if (b[l] != 0) bs[b[l]] = 1;
            l++;
        }
        while(r >= l && r % K != 0){
            if (b[r] != 0) bs[b[r]] = 1;
            r--;
        }
        while(l <= r){
            bs |= bl[l / K];
            l += K;
        }
        for (int i = M; i < p.size(); i++){
            if (bs[i]){
                ans = ans * p[i] % mod;
            }
        }
        cout << ans << '\n';
        last = ans;
    }
}


#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#include <atcoder/all>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
//using namespace atcoder;

typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 100020;
const int K = 300;
const int mod = 1e9 + 7;
const int M = 90;
int st[90][N][20];
int g[N], b[N + N];
int a[90][N];
bitset <20000> bl[200];
int binpow(int x, int y){
    int res = 1;
    while(y){
        if (y % 2) res = res * x % mod;
        y /= 2;
        x = x * x % mod;
    }
    return res;
}
int query(int k, int L, int R){
    int j = g[R - L + 1];
    int minimum = max(st[k][L][j], st[k][R - (1 << j) + 1][j]);
    return minimum;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    vector <int> p;
    map <int,int> f;
    for (int i = 2; i <= 2e5; i++){
        if (b[i] == 0){
            p.pb(i);
            f[i] = p.size() - 1;
            for (int j = i; j <= 2e5; j += i){
                b[j] = 1;
            }
        }
    }
    for (int i = 1; i <= 2e5; i++) b[i] = 0;
    g[1] = 0;
    for (int i = 2; i < N; i++)
        g[i] = g[i/2] + 1;
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++){
        int x;
        cin >> x;
        for (int j = 0; j < M; j++){
            int y = 0;
            while(x % p[j] == 0){
                y++;
                x /= p[j];
            }
            a[j][i] = y;
        }
        if (x != 1){
            b[i] = f[x];
        }
    }
    for (int k = 0; k < M; k++){
        for (int i = 0; i < N; i++)
            st[k][i][0] = a[k][i];
        for (int j = 1; j <= K; j++)
            for (int i = 0; i + (1 << j) < N; i++)
                st[k][i][j] = max(st[k][i][j-1], st[k][i + (1 << (j - 1))][j - 1]);
    }
    int q;
    cin >> q;
    int last = 0;
    for (int i = 1; i < n; i += K){
        for (int j = 1; j < i + K; j++){
            if (b[j] != 0) bl[i / K][b[j]] = 1;
        }
    }
    while(q--){
        int x, y, l, r;
        cin >> x >> y;
        l = (last + x) % n + 1;
        r = (last + y) % n + 1;
        if (l > r) swap(l, r);
        int ans = 1;
        for (int i = 0; i < M; i++){
            int z = query(i, l, r);
            ans = ans * binpow(p[i], z) % mod;
        }
        bitset <20000> bs;
        while(l <= r && l % K != 1){
            if (b[l] != 0) bs[b[l]] = 1;
            l++;
        }
        while(r >= l && r % K != 0){
            if (b[r] != 0) bs[b[r]] = 1;
            r--;
        }
        while(l <= r){
            bs |= bl[l / K];
            l += K;
        }
        for (int i = M; i < p.size(); i++){
            if (bs[i]) ans = ans * p[i] % mod;
        }
        cout << ans << '\n';
        last = ans;
    }
}


#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#include <atcoder/all>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
//using namespace atcoder;

typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 103020;
const int K = 300;
const int KK = 18;
const int mod = 1e9 + 7;
const int M = 90;
short st[90][N][20];
int g[N], b[N + N];
int a[90][N];
unsigned short bl[400][20000];
int binpow(int x, int y){
    int res = 1;
    while(y){
        if (y % 2) res = res * x % mod;
        y /= 2;
        x = x * x % mod;
    }
    return res;
}
int query(int k, int L, int R){
    int j = g[R - L + 1];
    int minimum = max(st[k][L][j], st[k][R - (1 << j) + 1][j]);
    return minimum;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    vector <int> p;
    map <int,int> f;
    for (int i = 2; i <= 2e5; i++){
        if (b[i] == 0){
            p.pb(i);
            f[i] = p.size() - 1;
            for (int j = i; j <= 2e5; j += i){
                b[j] = 1;
            }
        }
    }
    for (int i = 1; i <= 2e5; i++) b[i] = 0;
    g[1] = 0;
    for (int i = 2; i < N; i++)
        g[i] = g[i/2] + 1;
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++){
        int x;
        cin >> x;
        for (int j = 0; j < M; j++){
            int y = 0;
            while(x % p[j] == 0){
                y++;
                x /= p[j];
            }
            a[j][i] = y;
        }
        if (x != 1){
            b[i] = f[x];
        }
    }
    for (int k = 0; k < M; k++){
        for (int i = 0; i < N; i++)
            st[k][i][0] = a[k][i];
        for (int j = 1; j <= KK; j++)
            for (int i = 0; i + (1 << j) < N; i++)
                st[k][i][j] = max(st[k][i][j-1], st[k][i + (1 << (j - 1))][j - 1]);
    }
    int q;
    cin >> q;
    int last = 0;
    for (int i = 1; i <= n; i += K){
        for (int j = M; j < p.size(); j++){
            bl[i / K][j] = n + 1;
        }
        for (int j = i; j <= n; j++){
            bl[i / K][b[j]] = min(bl[i / K][b[j]], (unsigned short)j);
        }
    }
    while(q--){
        int x, y, l, r;
        cin >> x >> y;
        l = (last + x) % n + 1;
        r = (last + y) % n + 1;
        if (l > r) swap(l, r);
        int ans = 1;
        for (int i = 0; i < M; i++){
            int z = query(i, l, r);
            ans = ans * binpow(p[i], z) % mod;
        }
        bitset <20000> bs;
        while(l <= r && l % K != 1){
            if (b[l] != 0) bs[b[l]] = 1;
            l++;
        }
        for (int j = M; j < p.size(); j++){
            if (bl[l / K][j] <= r) bs[j] = 1;
        }
        for (int i = M; i < p.size(); i++){
            if (bs[i]){
                ans = ans * p[i] % mod;
            }
        }
        cout << ans << '\n';
        last = ans;
    }
}


#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#include <atcoder/all>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
//using namespace atcoder;

typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 103020;
const int K = 300;
const int KK = 18;
const int mod = 1e9 + 7;
const int M = 90;
short st[90][N][20];
int g[N], b[N + N];
int a[90][N];
bitset <20000> bl[400];
int binpow(int x, int y){
    int res = 1;
    while(y){
        if (y % 2) res = res * x % mod;
        y /= 2;
        x = x * x % mod;
    }
    return res;
}
int query(int k, int L, int R){
    int j = g[R - L + 1];
    int minimum = max(st[k][L][j], st[k][R - (1 << j) + 1][j]);
    return minimum;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    vector <int> p;
    map <int,int> f;
    for (int i = 2; i <= 2e5; i++){
        if (b[i] == 0){
            p.pb(i);
            f[i] = p.size() - 1;
            for (int j = i; j <= 2e5; j += i){
                b[j] = 1;
            }
        }
    }
    for (int i = 1; i <= 2e5; i++) b[i] = 0;
    g[1] = 0;
    for (int i = 2; i < N; i++)
        g[i] = g[i/2] + 1;
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++){
        int x;
        cin >> x;
        for (int j = 0; j < M; j++){
            int y = 0;
            while(x % p[j] == 0){
                y++;
                x /= p[j];
            }
            a[j][i] = y;
        }
        if (x != 1){
            b[i] = f[x];
        }
    }
    for (int k = 0; k < M; k++){
        for (int i = 0; i < N; i++)
            st[k][i][0] = a[k][i];
        for (int j = 1; j <= KK; j++)
            for (int i = 0; i + (1 << j) < N; i++)
                st[k][i][j] = max(st[k][i][j-1], st[k][i + (1 << (j - 1))][j - 1]);
    }
    int q;
    cin >> q;
    int last = 0;
    for (int i = 1; i <= n; i += K){
        for (int j = i; j < i + K; j++){
            if (b[j] != 0) bl[i / K][b[j]] = 1;
        }
    }
    while(q--){
        int x, y, l, r;
        cin >> x >> y;
        l = (last + x) % n + 1;
        r = (last + y) % n + 1;
        if (l > r) swap(l, r);
        int ans = 1;
        for (int i = 0; i < M; i++){
            int z = query(i, l, r);
            ans = ans * binpow(p[i], z) % mod;
        }
        bitset <20000> bs;
        while(l <= r && l % K != 1){
            if (b[l] != 0) bs[b[l]] = 1;
            l++;
        }
        while(r >= l && r % K != 0){
            if (b[r] != 0) bs[b[r]] = 1;
            r--;
        }
        while(l <= r){
            bs |= bl[l / K];
            l += K;
        }
        for (int i = M; i < p.size(); i++){
            if (bs[i]){
                ans = ans * p[i] % mod;
            }
        }
        cout << ans << '\n';
        last = ans;
    }
}


#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#include <atcoder/all>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
//using namespace atcoder;

typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 100020;
const int K = 300;
const int KK = 18;
const int mod = 1e9 + 7;
const int M = 90;
short st[90][N][20];
int g[N], b[N + N];
int a[90][N];
bitset <20000> bl[400];
int binpow(int x, int y){
    int res = 1;
    while(y){
        if (y % 2) res = res * x % mod;
        y /= 2;
        x = x * x % mod;
    }
    return res;
}
int query(int k, int L, int R){
    int j = g[R - L + 1];
    int minimum = max(st[k][L][j], st[k][R - (1 << j) + 1][j]);
    return minimum;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    vector <int> p;
    map <int,int> f;
    for (int i = 2; i <= 2e5; i++){
        if (b[i] == 0){
            p.pb(i);
            f[i] = p.size() - 1;
            for (int j = i; j <= 2e5; j += i){
                b[j] = 1;
            }
        }
    }
    for (int i = 1; i <= 2e5; i++) b[i] = 0;
    g[1] = 0;
    for (int i = 2; i < N; i++)
        g[i] = g[i/2] + 1;
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++){
        int x;
        cin >> x;
        for (int j = 0; j < M; j++){
            int y = 0;
            while(x % p[j] == 0){
                y++;
                x /= p[j];
            }
            a[j][i] = y;
        }
        if (x != 1){
            b[i] = f[x];
        }
    }
    for (int k = 0; k < M; k++){
        for (int i = 0; i < N; i++)
            st[k][i][0] = a[k][i];
        for (int j = 1; j <= KK; j++)
            for (int i = 0; i + (1 << j) < N; i++)
                st[k][i][j] = max(st[k][i][j-1], st[k][i + (1 << (j - 1))][j - 1]);
    }
    int q;
    cin >> q;
    int last = 0;
    for (int i = 1; i < n; i += K){
        for (int j = 1; j < i + K; j++){
            if (b[j] != 0) bl[i / K][b[j]] = 1;
        }
    }
    while(q--){
        int x, y, l, r;
        cin >> x >> y;
        l = (last + x) % n + 1;
        r = (last + y) % n + 1;
        if (l > r) swap(l, r);
        int ans = 1;
        for (int i = 0; i < M; i++){
            int z = query(i, l, r);
            ans = ans * binpow(p[i], z) % mod;
        }
        bitset <20000> bs;
        while(l <= r && l % K != 1){
            if (b[l] != 0) bs[b[l]] = 1;
            l++;
        }
        while(r >= l && r % K != 0){
            if (b[r] != 0) bs[b[r]] = 1;
            r--;
        }
        while(l <= r){
            bs |= bl[l / K];
            l += K;
        }
        for (int i = M; i < p.size(); i++){
            if (bs[i]) ans = ans * p[i] % mod;
        }
        cout << ans << '\n';
        last = ans;
    }
}


#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#include <atcoder/all>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
//using namespace atcoder;

typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 103020;
const int K = 300;
const int KK = 18;
const int mod = 1e9 + 7;
const int M = 90;
short st[90][N][20];
int g[N], b[N + N];
int a[90][N];
unsigned short bl[400][20000];
int binpow(int x, int y){
    int res = 1;
    while(y){
        if (y % 2) res = res * x % mod;
        y /= 2;
        x = x * x % mod;
    }
    return res;
}
int query(int k, int L, int R){
    int j = g[R - L + 1];
    int minimum = max(st[k][L][j], st[k][R - (1 << j) + 1][j]);
    return minimum;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    vector <int> p;
    map <int,int> f;
    for (int i = 2; i <= 2e5; i++){
        if (b[i] == 0){
            p.pb(i);
            f[i] = p.size() - 1;
            for (int j = i; j <= 2e5; j += i){
                b[j] = 1;
            }
        }
    }
    for (int i = 1; i <= 2e5; i++) b[i] = 0;
    g[1] = 0;
    for (int i = 2; i < N; i++)
        g[i] = g[i/2] + 1;
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++){
        int x;
        cin >> x;
        for (int j = 0; j < M; j++){
            int y = 0;
            while(x % p[j] == 0){
                y++;
                x /= p[j];
            }
            a[j][i] = y;
        }
        if (x != 1){
            b[i] = f[x];
        }
    }
    for (int k = 0; k < M; k++){
        for (int i = 0; i < N; i++)
            st[k][i][0] = a[k][i];
        for (int j = 1; j <= KK; j++)
            for (int i = 0; i + (1 << j) < N; i++)
                st[k][i][j] = max(st[k][i][j-1], st[k][i + (1 << (j - 1))][j - 1]);
    }
    int q;
    cin >> q;
    int last = 0;
    for (int i = 1; i <= n; i += K){
        for (int j = M; j < p.size(); j++){
            bl[i / K][j] = n + 1;
        }
        for (int j = i; j <= n; j++){
            bl[i / K][b[j]] = min(bl[i / K][b[j]], (unsigned short)j);
        }
    }
    while(q--){
        int x, y, l, r;
        cin >> x >> y;
        l = (last + x) % n + 1;
        r = (last + y) % n + 1;
        if (l > r) swap(l, r);
        int ans = 1;
        for (int i = 0; i < M; i++){
            int z = query(i, l, r);
            ans = ans * binpow(p[i], z) % mod;
        }
        bitset <20000> bs;
        while(l <= r && l % K != 1){
            if (b[l] != 0) bs[b[l]] = 1;
            l++;
        }
        for (int j = M; l <= r && j < p.size(); j++){
            if (bl[l / K][j] <= r) bs[j] = 1;
        }
        for (int i = M; i < p.size(); i++){
            if (bs[i]){
                ans = ans * p[i] % mod;
            }
        }
        cout << ans << '\n';
        last = ans;
    }
}


#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#include <atcoder/all>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
//using namespace atcoder;

typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 103020;
const int K = 300;
const int KK = 18;
const int mod = 1e9 + 7;
const int M = 90;
char st[90][N][20];
int g[N], b[N + N];
int a[90][N];
int pr[N], w[2 * N];
vector <pair<pair<int,int>,int>> t[N];
int binpow(int x, int y){
    int res = 1;
    while(y){
        if (y % 2) res = res * x % mod;
        y /= 2;
        x = x * x % mod;
    }
    return res;
}
int query(int k, int L, int R){
    int j = g[R - L + 1];
    int minimum = max(st[k][L][j], st[k][R - (1 << j) + 1][j]);
    return minimum;
}
int tquery(int v, int tl, int tr, int l, int r, int x){
    if (l > tr || r < tl) return 1;
    if (l <= tl && r >= tr){
        if (t[v][0].F.F >= x) return 1;
        int k = (int)(lower_bound(t[v].begin(), t[v].end(), make_pair(make_pair(x, -1LL), 1LL)) - t[v].begin()) - 1;
        return t[v][k].S;
    }
    int mid = (tr + tl) / 2;
    return tquery(v + v, tl, mid, l, r, x) * tquery(v + v + 1, mid + 1, tr, l, r, x);
}
void build(int v, int tl, int tr){
    if (tl == tr){
        t[v].pb(make_pair(make_pair(pr[tl], b[tl]), b[tl]));
        return;
    }
    int mid = (tl + tr) / 2;
    build(v + v, tl, mid);
    build(v + v + 1, mid + 1, tr);
    for (auto x: t[v + v]) t[v].pb(x);
    for (auto x: t[v + v + 1]) t[v].pb(x);
    sort(t[v].begin(), t[v].end());
    int c = 1;
    for (int i = 0; i < t[v].size(); i++){
        c = c * t[v][i].F.S % mod;
        t[v][i].S = c;
    }
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    vector <int> p;
    map <int,int> f;
    for (int i = 2; i <= 2e5; i++){
        if (b[i] == 0){
            p.pb(i);
            f[i] = p.size() - 1;
            for (int j = i; j <= 2e5; j += i){
                b[j] = 1;
            }
        }
    }
    for (int i = 1; i <= 2e5; i++) b[i] = 0;
    g[1] = 0;
    for (int i = 2; i < N; i++)
        g[i] = g[i/2] + 1;
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++){
        int x;
        cin >> x;
        for (int j = 0; j < M; j++){
            int y = 0;
            while(x % p[j] == 0){
                y++;
                x /= p[j];
            }
            a[j][i] = y;
        }
        b[i] = x;
    }
    for (int i = 1; i <= 2e5; i++) w[i] = -1;
    for (int i = 1; i <= n; i++){
        pr[i] = w[b[i]];
        w[b[i]] = i;
    }
    for (int k = 0; k < M; k++){
        for (int i = 0; i < N; i++)
            st[k][i][0] = a[k][i];
        for (int j = 1; j <= KK; j++)
            for (int i = 0; i + (1 << j) < N; i++)
                st[k][i][j] = max(st[k][i][j-1], st[k][i + (1 << (j - 1))][j - 1]);
    }
    int q;
    cin >> q;
    int last = 0;
    build(1, 1, n);
    while(q--){
        int x, y, l, r;
        cin >> x >> y;
        l = (last + x) % n + 1;
        r = (last + y) % n + 1;
        if (l > r) swap(l, r);
        int ans = 1;
        for (int i = 0; i < M; i++){
            int z = query(i, l, r);
            ans = ans * binpow(p[i], z) % mod;
        }
        ans = ans * tquery(1, 1, n, l, r, l) % mod;
        cout << ans << '\n';
        last = ans;
    }
}


#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#include <atcoder/all>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
//using namespace atcoder;

typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 103020;
const int K = 300;
const int KK = 18;
const int mod = 1e9 + 7;
const int M = 90;
char st[90][N][20];
int g[N], b[N + N];
int a[90][N];
int pr[N], w[2 * N];
vector <pair<pair<int,int>,int>> t[5 * N];
int binpow(int x, int y){
    int res = 1;
    while(y){
        if (y % 2) res = res * x % mod;
        y /= 2;
        x = x * x % mod;
    }
    return res;
}
int query(int k, int L, int R){
    int j = g[R - L + 1];
    int minimum = max(st[k][L][j], st[k][R - (1 << j) + 1][j]);
    return minimum;
}
int tquery(int v, int tl, int tr, int l, int r, int x){
    if (l > tr || r < tl) return 1;
    if (l <= tl && r >= tr){
        if (t[v][0].F.F >= x) return 1;
        int k = (int)(lower_bound(t[v].begin(), t[v].end(), make_pair(make_pair(x, -1LL), 1LL)) - t[v].begin()) - 1;
        return t[v][k].S;
    }
    int mid = (tr + tl) / 2;
    return tquery(v + v, tl, mid, l, r, x) * tquery(v + v + 1, mid + 1, tr, l, r, x) % mod;
}
void build(int v, int tl, int tr){
    if (tl == tr){
        t[v].pb(make_pair(make_pair(pr[tl], b[tl]), b[tl]));
        return;
    }
    int mid = (tl + tr) / 2;
    build(v + v, tl, mid);
    build(v + v + 1, mid + 1, tr);
    for (auto x: t[v + v]) t[v].pb(x);
    for (auto x: t[v + v + 1]) t[v].pb(x);
    sort(t[v].begin(), t[v].end());
    int c = 1;
    for (int i = 0; i < t[v].size(); i++){
        c = c * t[v][i].F.S % mod;
        t[v][i].S = c;
    }
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    vector <int> p;
    map <int,int> f;
    for (int i = 2; i <= 2e5; i++){
        if (b[i] == 0){
            p.pb(i);
            f[i] = p.size() - 1;
            for (int j = i; j <= 2e5; j += i){
                b[j] = 1;
            }
        }
    }
    for (int i = 1; i <= 2e5; i++) b[i] = 0;
    g[1] = 0;
    for (int i = 2; i < N; i++)
        g[i] = g[i/2] + 1;
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++){
        int x;
        cin >> x;
        for (int j = 0; j < M; j++){
            int y = 0;
            while(x % p[j] == 0){
                y++;
                x /= p[j];
            }
            a[j][i] = y;
        }
        b[i] = x;
    }
    for (int i = 1; i <= 2e5; i++) w[i] = -1;
    for (int i = 1; i <= n; i++){
        pr[i] = w[b[i]];
        w[b[i]] = i;
    }
    for (int k = 0; k < M; k++){
        for (int i = 0; i < N; i++)
            st[k][i][0] = a[k][i];
        for (int j = 1; j <= KK; j++)
            for (int i = 0; i + (1 << j) < N; i++)
                st[k][i][j] = max(st[k][i][j-1], st[k][i + (1 << (j - 1))][j - 1]);
    }
    int q;
    cin >> q;
    int last = 0;
    build(1, 1, n);
    while(q--){
        int x, y, l, r;
        cin >> x >> y;
        l = (last + x) % n + 1;
        r = (last + y) % n + 1;
        if (l > r) swap(l, r);
        int ans = 1;
        for (int i = 0; i < M; i++){
            int z = query(i, l, r);
            ans = ans * binpow(p[i], z) % mod;
        }
        ans = ans * tquery(1, 1, n, l, r, l) % mod;
        cout << ans << '\n';
        last = ans;
    }
}


#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#include <atcoder/all>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
//using namespace atcoder;

typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 100020;
const int K = 300;
const int mod = 1e9 + 7;
const int M = 90;
int st[90][N][20];
int g[N], b[N + N];
int a[90][N];
bitset <20000> bl[200];
int binpow(int x, int y){
    int res = 1;
    while(y){
        if (y % 2) res = res * x % mod;
        y /= 2;
        x = x * x % mod;
    }
    return res;
}
int query(int k, int L, int R){
    int j = g[R - L + 1];
    int minimum = max(st[k][L][j], st[k][R - (1 << j) + 1][j]);
    return minimum;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    /freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    vector <int> p;
    map <int,int> f;
    for (int i = 2; i <= 2e5; i++){
        if (b[i] == 0){
            p.pb(i);
            f[i] = p.size() - 1;
            for (int j = i; j <= 2e5; j += i){
                b[j] = 1;
            }
        }
    }
    for (int i = 1; i <= 2e5; i++) b[i] = 0;
    g[1] = 0;
    for (int i = 2; i < N; i++)
        g[i] = g[i/2] + 1;
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++){
        int x;
        cin >> x;
        for (int j = 0; j < M; j++){
            int y = 0;
            while(x % p[j] == 0){
                y++;
                x /= p[j];
            }
            a[j][i] = y;
        }
        if (x != 1){
            b[i] = f[x];
        }
    }
    for (int k = 0; k < M; k++){
        for (int i = 0; i < N; i++)
            st[k][i][0] = a[k][i];
        for (int j = 1; j <= K; j++)
            for (int i = 0; i + (1 << j) < N; i++)
                st[k][i][j] = max(st[k][i][j-1], st[k][i + (1 << (j - 1))][j - 1]);
    }
    int q;
    cin >> q;
    int last = 0;
    for (int i = 1; i < n; i += K){
        for (int j = 1; j < i + K; j++){
            if (b[j] != 0) bl[i / K][b[j]] = 1;
        }
    }
    while(q--){
        int x, y, l, r;
        cin >> x >> y;
        l = (last + x) % n + 1;
        r = (last + y) % n + 1;
        if (l > r) swap(l, r);
        int ans = 1;
        for (int i = 0; i < M; i++){
            int z = query(i, l, r);
            ans = ans * binpow(p[i], z) % mod;
        }
        bitset <20000> bs;
        while(l <= r && l % K != 1){
            if (b[l] != 0) bs[b[l]] = 1;
            l++;
        }
        while(r >= l && r % K != 0){
            if (b[r] != 0) bs[b[r]] = 1;
            r--;
        }
        while(l <= r){
            bs |= bl[l / K];
            l += K;
        }
        for (int i = M; i < p.size(); i++){
            if (bs[i]) ans = ans * p[i] % mod;
        }
        cout << ans << '\n';
        last = ans;
    }
}


#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#include <atcoder/all>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
//using namespace atcoder;

typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 103020;
const int K = 300;
const int KK = 18;
const int mod = 1e9 + 7;
const int M = 90;
char st[90][N][20];
int g[N], b[N + N];
int a[90][N];
int pr[N], w[2 * N];
vector <pair<pair<int,int>,int>> t[N];
int binpow(int x, int y){
    int res = 1;
    while(y){
        if (y % 2) res = res * x % mod;
        y /= 2;
        x = x * x % mod;
    }
    return res;
}
int query(int k, int L, int R){
    int j = g[R - L + 1];
    int minimum = max(st[k][L][j], st[k][R - (1 << j) + 1][j]);
    return minimum;
}
int tquery(int v, int tl, int tr, int l, int r, int x){
    if (l > tr || r < tl) return 1;
    if (l <= tl && r >= tr){
        if (t[v][0].F.F >= x) return 1;
        int k = (int)(lower_bound(t[v].begin(), t[v].end(), make_pair(make_pair(x, -1LL), 1LL)) - t[v].begin()) - 1;
        return t[v][k].S;
    }
    int mid = (tr + tl) / 2;
    return tquery(v + v, tl, mid, l, r, x) * tquery(v + v + 1, mid + 1, tr, l, r, x) % mod;
}
void build(int v, int tl, int tr){
    if (tl == tr){
        t[v].pb(make_pair(make_pair(pr[tl], b[tl]), b[tl]));
        return;
    }
    int mid = (tl + tr) / 2;
    build(v + v, tl, mid);
    build(v + v + 1, mid + 1, tr);
    for (auto x: t[v + v]) t[v].pb(x);
    for (auto x: t[v + v + 1]) t[v].pb(x);
    sort(t[v].begin(), t[v].end());
    int c = 1;
    for (int i = 0; i < t[v].size(); i++){
        c = c * t[v][i].F.S % mod;
        t[v][i].S = c;
    }
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    vector <int> p;
    map <int,int> f;
    for (int i = 2; i <= 2e5; i++){
        if (b[i] == 0){
            p.pb(i);
            f[i] = p.size() - 1;
            for (int j = i; j <= 2e5; j += i){
                b[j] = 1;
            }
        }
    }
    for (int i = 1; i <= 2e5; i++) b[i] = 0;
    g[1] = 0;
    for (int i = 2; i < N; i++)
        g[i] = g[i/2] + 1;
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++){
        int x;
        cin >> x;
        for (int j = 0; j < M; j++){
            int y = 0;
            while(x % p[j] == 0){
                y++;
                x /= p[j];
            }
            a[j][i] = y;
        }
        b[i] = x;
    }
    for (int i = 1; i <= 2e5; i++) w[i] = -1;
    for (int i = 1; i <= n; i++){
        pr[i] = w[b[i]];
        w[b[i]] = i;
    }
    for (int k = 0; k < M; k++){
        for (int i = 0; i < N; i++)
            st[k][i][0] = a[k][i];
        for (int j = 1; j <= KK; j++)
            for (int i = 0; i + (1 << j) < N; i++)
                st[k][i][j] = max(st[k][i][j-1], st[k][i + (1 << (j - 1))][j - 1]);
    }
    int q;
    cin >> q;
    int last = 0;
    build(1, 1, n);
    while(q--){
        int x, y, l, r;
        cin >> x >> y;
        l = (last + x) % n + 1;
        r = (last + y) % n + 1;
        if (l > r) swap(l, r);
        int ans = 1;
        for (int i = 0; i < M; i++){
            int z = query(i, l, r);
            ans = ans * binpow(p[i], z) % mod;
        }
        ans = ans * tquery(1, 1, n, l, r, l) % mod;
        cout << ans << '\n';
        last = ans;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define ar array<int,2>
#define inf 1000000000000000000
int mod=1e9+7;
int min(int a,int b){return (a<b)?a:b;}
int max(int a,int b){return (a>b)?a:b;}

map<array<int,2>,int> mp;
int fp(int a,int b){if(b==0) return 1;
  auto it=mp.find(array<int,2>{a,b});
  if(it!=mp.end())
    return (*it).second;
  int x=fp(a,b/2);x=(x*x)%mod;if(b&1) x=(x*a)%mod;return mp[{a,b}]=x;}

const int N=1e5+5;

const int mxA=2e5+5;

int prime[mxA]={0},last[mxA]={0};
int MAXN=sqrt(mxA);
vector<int> smlprime,large;

int a[N];

struct node
{
  int pw[86];
  vector<array<int,3>> v;
  // node()
  // {
  //   memset(pw,0,sizeof(pw));
  // }
};
void merge(node &a,node &b,node &c,bool ok=true)
{
  for(int i=0;i<smlprime.size();i++)
    c.pw[i]=max(a.pw[i],b.pw[i]);

  if(ok){

    int i=0;
    int j=0;

    while(i<a.v.size()&&j<b.v.size())
    {
      if(a.v[i][0]<b.v[j][0])
      {
        c.v.push_back(a.v[i]);
        i++;
      }
      else
      {
        c.v.push_back(b.v[j]);
        j++;
      }
    }
    while(i<a.v.size())
    {
        c.v.push_back(a.v[i]);
        i++;
    }
    while(j<b.v.size())
    {
        c.v.push_back(b.v[j]);
        j++;
    }
  }
  //  merge(a.v.begin(),a.v.end(),b.v.begin(),b.v.end(),c.v.begin());

}

vector<node> bit(4*N);
void build(int id,int l,int r)
{
  if(l==r)
  {
      for(int i=0;i<smlprime.size();i++)
        bit[id].pw[i]=1;
     // memset(bit[id].pw,1,sizeof(bit[id].pw));
      int x=a[l];

      while(x>1)
      {
        int p=prime[x],y=0,z=1;
        while(x%p==0)
          y++,x/=p,z=(z*p);
        if(p<=MAXN)
        {
          int idx=lower_bound(smlprime.begin(),smlprime.end(),p)-smlprime.begin();
          bit[id].pw[idx]=z;
        }
        else
        {
         // cout<<p<<endl;
          bit[id].v.push_back({last[p],p,p});
          last[p]=l;
        }
      }
      return;
  }
  int mid=(l+r)/2;
  build(2*id,l,mid);
  build(2*id+1,mid+1,r);
  merge(bit[2*id],bit[2*id+1],bit[id]);
  int x=1;
  for(auto &i:bit[id].v)
    i[2]=(i[1]*x)%mod,x=i[2];
}

int ans;

node nd;

void get(int id,int l,int r,int L,int R)
{
  if(R<l||r<L){
    return ;
  }
  if(L<=l&&r<=R)
  {
         for(int i=0;i<smlprime.size();i++)
        nd.pw[i]=max(nd.pw[i],bit[id].pw[i]);

    // for(auto i:bit[id].v)
    //   cout<<i[0]<<" "<<i[1]<<" "<<i[2]<<endl;

  //  cout<<endl;
    int lw=0,hg=bit[id].v.size()-1;
    int r=1;
    if(bit[id].v.size())
    while(lw<=hg)
    {
      int mid=(lw+hg)/2;
      if(bit[id].v[mid][0]<L)
      {
        r=bit[id].v[mid][2];
        lw=mid+1;
      }
      else{
        hg=mid-1;
      }
    }
    ans=(ans*r)%mod;
    return;
  }
  int mid=(l+r)/2;
  get(2*id,l,mid,L,R);
  get(2*id+1,mid+1,r,L,R);
}

void upd(int id,int l,int r,int L,int R,int v)
{
  if(R<l||r<L)
    return;
  if(L<=l&&r<=R)
  {

    return;
  }
  int mid=(l+r)/2;
  upd(2*id,l,mid,L,R,v);
  upd(2*id+1,mid+1,r,L,R,v);
  merge(bit[2*id],bit[2*id+1],bit[id]);
}

signed main() {
  srand(time(0));
 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 prime[1]=1;
 for(int i=2;i<mxA;i++){
  if(prime[i]==0)
  {
    for(int j=1;j*i<mxA;j++)
      prime[j*i]=i;
    if(i<=MAXN)
      smlprime.push_back(i);
    else
      large.push_back(i);
  }
 }

// cout<<smlprime.size()<<endl;

 int n;
 //n=1e5;
 cin>>n;
 for(int i=1;i<=n;i++)
 {
  //a[i]=rand()%((int)1e5)+1;
  cin>>a[i];
 }

 build(1,1,n);

 int q,last=0;
 cin>>q;
 while(q--)
 {
  int l,r;
  cin>>l>>r;
  //l=rand();
  //r=rand();
   l=(last+l)%n+1;
   r=(last+r)%n+1;
   if(l>r)
    swap(l,r);
  //cout<<l<<" "<<r<<endl;

  ans=1;
  for(int i=0;i<smlprime.size();i++)
        nd.pw[i]=1;

  get(1,1,n,l,r);
  //cout<<ans<<endl;
  for(int i=0;i<smlprime.size();i++)
  {
    ans=(ans*nd.pw[i]);
    if(ans>=mod)ans%=mod;
  }
  cout<<ans<<endl;
  last=ans;
 }

}


#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define ar array<int,2>
#define inf 1000000000000000000
int mod=1e9+7;
int min(int a,int b){return (a<b)?a:b;}
int max(int a,int b){return (a>b)?a:b;}

map<array<int,2>,int> mp;
int fp(int a,int b){if(b==0) return 1;
  auto it=mp.find(array<int,2>{a,b});
  if(it!=mp.end())
    return (*it).second;
  int x=fp(a,b/2);x=(x*x)%mod;if(b&1) x=(x*a)%mod;return mp[{a,b}]=x;}

const int N=1e5+5;

const int mxA=2e5+5;

int prime[mxA]={0},last[mxA]={0};
int MAXN=sqrt(mxA);
vector<int> smlprime,large;

int a[N];

struct node
{
  int pw[86];
  vector<array<int,3>> v;
  // node()
  // {
  //   memset(pw,0,sizeof(pw));
  // }
};
node merge(node a,node b,bool ok=true)
{
  node c;
  for(int i=0;i<smlprime.size();i++)
    c.pw[i]=max(a.pw[i],b.pw[i]);

  if(ok){

    int i=0;
    int j=0;

    while(i<a.v.size()&&j<b.v.size())
    {
      if(a.v[i][0]<b.v[j][0])
      {
        c.v.push_back(a.v[i]);
        i++;
      }
      else
      {
        c.v.push_back(b.v[j]);
        j++;
      }
    }
    while(i<a.v.size())
    {
        c.v.push_back(a.v[i]);
        i++;
    }
    while(j<b.v.size())
    {
        c.v.push_back(b.v[j]);
        j++;
    }
  }
  //  merge(a.v.begin(),a.v.end(),b.v.begin(),b.v.end(),c.v.begin());
  return c;
}

vector<node> bit(4*N);
void build(int id,int l,int r)
{
  if(l==r)
  {
      memset(bit[id].pw,0,sizeof(bit[id].pw));
      int x=a[l];

      while(x>1)
      {
        int p=prime[x],y=0;
        while(x%p==0)
          y++,x/=p;
        if(p<=MAXN)
        {
          int idx=lower_bound(smlprime.begin(),smlprime.end(),p)-smlprime.begin();
          bit[id].pw[idx]=y;
        }
        else
        {
         // cout<<p<<endl;
          bit[id].v.push_back({last[p],p,p});
          last[p]=l;
        }
      }
      return;
  }
  int mid=(l+r)/2;
  build(2*id,l,mid);
  build(2*id+1,mid+1,r);
  bit[id]=merge(bit[2*id],bit[2*id+1]);
  int x=1;
  for(auto &i:bit[id].v)
    i[2]=(i[1]*x)%mod,x=i[2];
}

int ans;

node get(int id,int l,int r,int L,int R)
{
  if(R<l||r<L){
    node c;
      memset(c.pw,0,sizeof(c.pw));
    return c;
  }
  if(L<=l&&r<=R)
  {

    // for(auto i:bit[id].v)
    //   cout<<i[0]<<" "<<i[1]<<" "<<i[2]<<endl;

  //  cout<<endl;
    int lw=0,hg=bit[id].v.size()-1;
    int r=1;
    if(bit[id].v.size())
    while(lw<=hg)
    {
      int mid=(lw+hg)/2;
      if(bit[id].v[mid][0]<L)
      {
        r=bit[id].v[mid][2];
        lw=mid+1;
      }
      else{
        hg=mid-1;
      }
    }
    ans=(ans*r)%mod;
    return bit[id];
  }
  int mid=(l+r)/2;
  return merge(get(2*id,l,mid,L,R),get(2*id+1,mid+1,r,L,R));
}

void upd(int id,int l,int r,int L,int R,int v)
{
  if(R<l||r<L)
    return;
  if(L<=l&&r<=R)
  {

    return;
  }
  int mid=(l+r)/2;
  upd(2*id,l,mid,L,R,v);
  upd(2*id+1,mid+1,r,L,R,v);
  bit[id]=merge(bit[2*id],bit[2*id+1]);
}

signed main() {
 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 prime[1]=1;
 for(int i=2;i<mxA;i++){
  if(prime[i]==0)
  {
    for(int j=1;j*i<mxA;j++)
      prime[j*i]=i;
    if(i<=MAXN)
      smlprime.push_back(i);
    else
      large.push_back(i);
  }
 }

// cout<<smlprime.size()<<endl;

 int n;
 cin>>n;
 for(int i=1;i<=n;i++)
 {
  cin>>a[i];
 }

 build(1,1,n);

 int q,last=0;
 cin>>q;
 while(q--)
 {
  int l,r;
  cin>>l>>r;

   l=(last+l)%n+1;
   r=(last+r)%n+1;
   if(l>r)
    swap(l,r);
 // cout<<l<<" "<<r<<endl;

  ans=1;
  node nd=get(1,1,n,l,r);
  for(int i=0;i<smlprime.size();i++)
  {
    ans=(ans*fp(smlprime[i],nd.pw[i]));
    if(ans>=mod)ans%=mod;
  }
  cout<<ans<<endl;
  last=ans;
 }

}


#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define ar array<int,2>
#define inf 1000000000000000000
int mod=1e9+7;
int min(int a,int b){return (a<b)?a:b;}
int max(int a,int b){return (a>b)?a:b;}

map<array<int,2>,int> mp;
int fp(int a,int b){if(b==0) return 1;
  auto it=mp.find(array<int,2>{a,b});
  if(it!=mp.end())
    return (*it).second;
  int x=fp(a,b/2);x=(x*x)%mod;if(b&1) x=(x*a)%mod;return mp[{a,b}]=x;}

const int N=1e5+5;

const int mxA=2e5+5;

int prime[mxA]={0},last[mxA]={0};
int MAXN=sqrt(mxA);
vector<int> smlprime,large;

int a[N];

struct node
{
  int pw[86];
  vector<array<int,3>> v;
  // node()
  // {
  //   memset(pw,0,sizeof(pw));
  // }
};
node merge(node a,node b,bool ok=true)
{
  node c;
  for(int i=0;i<smlprime.size();i++)
    c.pw[i]=max(a.pw[i],b.pw[i]);

  if(ok){

    int i=0;
    int j=0;

    while(i<a.v.size()&&j<b.v.size())
    {
      if(a.v[i][0]<b.v[j][0])
      {
        c.v.push_back(a.v[i]);
        i++;
      }
      else
      {
        c.v.push_back(b.v[j]);
        j++;
      }
    }
    while(i<a.v.size())
    {
        c.v.push_back(a.v[i]);
        i++;
    }
    while(j<b.v.size())
    {
        c.v.push_back(b.v[j]);
        j++;
    }
  }
  //  merge(a.v.begin(),a.v.end(),b.v.begin(),b.v.end(),c.v.begin());
  return c;
}

vector<node> bit(4*N);
void build(int id,int l,int r)
{
  if(l==r)
  {
      for(int i=0;i<smlprime.size();i++)
        bit[id].pw[i]=1;
     // memset(bit[id].pw,1,sizeof(bit[id].pw));
      int x=a[l];

      while(x>1)
      {
        int p=prime[x],y=0,z=1;
        while(x%p==0)
          y++,x/=p,z=(z*p);
        if(p<=MAXN)
        {
          int idx=lower_bound(smlprime.begin(),smlprime.end(),p)-smlprime.begin();
          bit[id].pw[idx]=z;
        }
        else
        {
         // cout<<p<<endl;
          bit[id].v.push_back({last[p],p,p});
          last[p]=l;
        }
      }
      return;
  }
  int mid=(l+r)/2;
  build(2*id,l,mid);
  build(2*id+1,mid+1,r);
  bit[id]=merge(bit[2*id],bit[2*id+1]);
  int x=1;
  for(auto &i:bit[id].v)
    i[2]=(i[1]*x)%mod,x=i[2];
}

int ans;

node get(int id,int l,int r,int L,int R)
{
  if(R<l||r<L){
    node c;
     for(int i=0;i<smlprime.size();i++)
        c.pw[i]=1;
     // memset(c.pw,1,sizeof(c.pw));
    return c;
  }
  if(L<=l&&r<=R)
  {

    // for(auto i:bit[id].v)
    //   cout<<i[0]<<" "<<i[1]<<" "<<i[2]<<endl;

  //  cout<<endl;
    int lw=0,hg=bit[id].v.size()-1;
    int r=1;
    if(bit[id].v.size())
    while(lw<=hg)
    {
      int mid=(lw+hg)/2;
      if(bit[id].v[mid][0]<L)
      {
        r=bit[id].v[mid][2];
        lw=mid+1;
      }
      else{
        hg=mid-1;
      }
    }
    ans=(ans*r)%mod;
    return bit[id];
  }
  int mid=(l+r)/2;
  return merge(get(2*id,l,mid,L,R),get(2*id+1,mid+1,r,L,R),false);
}

void upd(int id,int l,int r,int L,int R,int v)
{
  if(R<l||r<L)
    return;
  if(L<=l&&r<=R)
  {

    return;
  }
  int mid=(l+r)/2;
  upd(2*id,l,mid,L,R,v);
  upd(2*id+1,mid+1,r,L,R,v);
  bit[id]=merge(bit[2*id],bit[2*id+1]);
}

signed main() {
  srand(time(0));
 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 prime[1]=1;
 for(int i=2;i<mxA;i++){
  if(prime[i]==0)
  {
    for(int j=1;j*i<mxA;j++)
      prime[j*i]=i;
    if(i<=MAXN)
      smlprime.push_back(i);
    else
      large.push_back(i);
  }
 }

// cout<<smlprime.size()<<endl;

 int n;
 //n=1e5;
 cin>>n;
 for(int i=1;i<=n;i++)
 {
//  a[i]=rand()%((int)1e5)+1;
  cin>>a[i];
 }

 build(1,1,n);

 int q,last=0;
 cin>>q;
 while(q--)
 {
  int l,r;
  cin>>l>>r;
 // l=rand();
 // r=rand();
   l=(last+l)%n+1;
   r=(last+r)%n+1;
   if(l>r)
    swap(l,r);
  //cout<<l<<" "<<r<<endl;

  ans=1;
  node nd=get(1,1,n,l,r);
  //cout<<ans<<endl;
  for(int i=0;i<smlprime.size();i++)
  {
    ans=(ans*nd.pw[i]);
    if(ans>=mod)ans%=mod;
  }
  cout<<ans<<endl;
  last=ans;
 }

}


#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define ar array<int,2>
#define inf 1000000000000000000
int mod=1e9+7;
int min(int a,int b){return (a<b)?a:b;}
int max(int a,int b){return (a>b)?a:b;}

map<array<int,2>,int> mp;
int fp(int a,int b){if(b==0) return 1;
  auto it=mp.find(array<int,2>{a,b});
  if(it!=mp.end())
    return (*it).second;
  int x=fp(a,b/2);x=(x*x)%mod;if(b&1) x=(x*a)%mod;return mp[{a,b}]=x;}

const int N=1e5+5;

const int mxA=2e5+5;

int prime[mxA]={0},last[mxA]={0};
int MAXN=sqrt(mxA);
vector<int> smlprime,large;

int a[N];

struct node
{
  int pw[86];
  vector<array<int,3>> v;
  // node()
  // {
  //   memset(pw,0,sizeof(pw));
  // }
};
node merge(node a,node b,bool ok=true)
{
  node c;
  for(int i=0;i<smlprime.size();i++)
    c.pw[i]=max(a.pw[i],b.pw[i]);

  if(ok){

    int i=0;
    int j=0;

    while(i<a.v.size()&&j<b.v.size())
    {
      if(a.v[i][0]<b.v[j][0])
      {
        c.v.push_back(a.v[i]);
        i++;
      }
      else
      {
        c.v.push_back(b.v[j]);
        j++;
      }
    }
    while(i<a.v.size())
    {
        c.v.push_back(a.v[i]);
        i++;
    }
    while(j<b.v.size())
    {
        c.v.push_back(b.v[j]);
        j++;
    }
  }
  //  merge(a.v.begin(),a.v.end(),b.v.begin(),b.v.end(),c.v.begin());
  return c;
}

vector<node> bit(4*N);
void build(int id,int l,int r)
{
  if(l==r)
  {
      memset(bit[id].pw,0,sizeof(bit[id].pw));
      int x=a[l];

      while(x>1)
      {
        int p=prime[x],y=0;
        while(x%p==0)
          y++,x/=p;
        if(p<=MAXN)
        {
          int idx=lower_bound(smlprime.begin(),smlprime.end(),p)-smlprime.begin();
          bit[id].pw[idx]=y;
        }
        else
        {
         // cout<<p<<endl;
          bit[id].v.push_back({last[p],p,p});
          last[p]=l;
        }
      }
      return;
  }
  int mid=(l+r)/2;
  build(2*id,l,mid);
  build(2*id+1,mid+1,r);
  bit[id]=merge(bit[2*id],bit[2*id+1]);
  int x=1;
  for(auto &i:bit[id].v)
    i[2]=(i[1]*x)%mod,x=i[2];
}

int ans;

node get(int id,int l,int r,int L,int R)
{
  if(R<l||r<L){
    node c;
      memset(c.pw,0,sizeof(c.pw));
    return c;
  }
  if(L<=l&&r<=R)
  {

    // for(auto i:bit[id].v)
    //   cout<<i[0]<<" "<<i[1]<<" "<<i[2]<<endl;

  //  cout<<endl;
    int lw=0,hg=bit[id].v.size()-1;
    int r=1;
    if(bit[id].v.size())
    while(lw<=hg)
    {
      int mid=(lw+hg)/2;
      if(bit[id].v[mid][0]<L)
      {
        r=bit[id].v[mid][2];
        lw=mid+1;
      }
      else{
        hg=mid-1;
      }
    }
    ans=(ans*r)%mod;
    return bit[id];
  }
  int mid=(l+r)/2;
  return merge(get(2*id,l,mid,L,R),get(2*id+1,mid+1,r,L,R),false);
}

void upd(int id,int l,int r,int L,int R,int v)
{
  if(R<l||r<L)
    return;
  if(L<=l&&r<=R)
  {

    return;
  }
  int mid=(l+r)/2;
  upd(2*id,l,mid,L,R,v);
  upd(2*id+1,mid+1,r,L,R,v);
  bit[id]=merge(bit[2*id],bit[2*id+1]);
}

signed main() {
 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 prime[1]=1;
 for(int i=2;i<mxA;i++){
  if(prime[i]==0)
  {
    for(int j=1;j*i<mxA;j++)
      prime[j*i]=i;
    if(i<=MAXN)
      smlprime.push_back(i);
    else
      large.push_back(i);
  }
 }

// cout<<smlprime.size()<<endl;

 int n;
 cin>>n;
 for(int i=1;i<=n;i++)
 {
  cin>>a[i];
 }

 build(1,1,n);

 int q,last=0;
 cin>>q;
 while(q--)
 {
  int l,r;
  cin>>l>>r;

   l=(last+l)%n+1;
   r=(last+r)%n+1;
   if(l>r)
    swap(l,r);
 // cout<<l<<" "<<r<<endl;

  ans=1;
  node nd=get(1,1,n,l,r);
  for(int i=0;i<smlprime.size();i++)
  {
    ans=(ans*fp(smlprime[i],nd.pw[i]));
    if(ans>=mod)ans%=mod;
  }
  cout<<ans<<endl;
  last=ans;
 }

}


#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define ar array<int,2>
#define inf 1000000000000000000
int mod=1e9+7;
int min(int a,int b){return (a<b)?a:b;}
int max(int a,int b){return (a>b)?a:b;}
int fp(int a,int b){if(b==0) return 1;int x=fp(a,b/2);x=(x*x)%mod;if(b&1) x=(x*a)%mod;return x;}

const int N=1e5+5;

const int mxA=2e5+5;

int prime[mxA]={0},last[mxA]={0};
int MAXN=sqrt(mxA);
vector<int> smlprime,large;

int a[N];

struct node
{
  int pw[86];
  vector<array<int,3>> v;
  node()
  {
    memset(pw,0,sizeof(pw));
  }
};
node merge(node a,node b,bool ok=true)
{
  node c;
  for(int i=0;i<smlprime.size();i++)
    c.pw[i]=max(a.pw[i],b.pw[i]);

  if(ok){
  c.v=a.v;
  for(auto i:b.v)
    c.v.push_back(i);
  sort(c.v.begin(),c.v.end());
  }
  //  merge(a.v.begin(),a.v.end(),b.v.begin(),b.v.end(),c.v.begin());
  return c;
}

vector<node> bit(4*N);
void build(int id,int l,int r)
{
  if(l==r)
  {

      int x=a[l];

      while(x>1)
      {
        int p=prime[x],y=0;
        while(x%p==0)
          y++,x/=p;
        if(p<=MAXN)
        {
          int idx=lower_bound(smlprime.begin(),smlprime.end(),p)-smlprime.begin();
          bit[id].pw[idx]=y;
        }
        else
        {
         // cout<<p<<endl;
          bit[id].v.push_back({last[p],p,p});
          last[p]=l;
        }
      }
      return;
  }
  int mid=(l+r)/2;
  build(2*id,l,mid);
  build(2*id+1,mid+1,r);
  bit[id]=merge(bit[2*id],bit[2*id+1]);
  int x=1;
  for(auto &i:bit[id].v)
    i[2]=(i[1]*x)%mod,x=i[2];
}

int ans;

node get(int id,int l,int r,int L,int R)
{
  if(R<l||r<L){
    node c;
    return c;
  }
  if(L<=l&&r<=R)
  {

    // for(auto i:bit[id].v)
    //   cout<<i[0]<<" "<<i[1]<<" "<<i[2]<<endl;

  //  cout<<endl;
    int lw=0,hg=bit[id].v.size()-1;
    int r=1;
    if(bit[id].v.size())
    while(lw<=hg)
    {
      int mid=(lw+hg)/2;
      if(bit[id].v[mid][0]<L)
      {
        r=bit[id].v[mid][2];
        lw=mid+1;
      }
      else{
        hg=mid-1;
      }
    }
    ans=(ans*r)%mod;
    return bit[id];
  }
  int mid=(l+r)/2;
  return merge(get(2*id,l,mid,L,R),get(2*id+1,mid+1,r,L,R));
}

void upd(int id,int l,int r,int L,int R,int v)
{
  if(R<l||r<L)
    return;
  if(L<=l&&r<=R)
  {

    return;
  }
  int mid=(l+r)/2;
  upd(2*id,l,mid,L,R,v);
  upd(2*id+1,mid+1,r,L,R,v);
  bit[id]=merge(bit[2*id],bit[2*id+1]);
}

signed main() {
 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 prime[1]=1;
 for(int i=2;i<mxA;i++){
  if(prime[i]==0)
  {
    for(int j=1;j*i<mxA;j++)
      prime[j*i]=i;
    if(i<=MAXN)
      smlprime.push_back(i);
    else
      large.push_back(i);
  }
 }

// cout<<smlprime.size()<<endl;

 int n;
 cin>>n;
 for(int i=1;i<=n;i++)
 {
  cin>>a[i];
 }

 build(1,1,n);

 int q,last=0;
 cin>>q;
 while(q--)
 {
  int l,r;
  cin>>l>>r;

   l=(last+l)%n+1;
   r=(last+r)%n+1;
   if(l>r)
    swap(l,r);
 // cout<<l<<" "<<r<<endl;

  ans=1;
  node nd=get(1,1,n,l,r);
  for(int i=0;i<smlprime.size();i++)
  {
    ans=(ans*fp(smlprime[i],nd.pw[i]));
    if(ans>=mod)ans%=mod;
  }
  cout<<ans<<endl;
  last=ans;
 }

}


#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define ar array<int,2>
#define inf 1000000000000000000
int mod=1e9+7;
int min(int a,int b){return (a<b)?a:b;}
int max(int a,int b){return (a>b)?a:b;}
int fp(int a,int b){if(b==0) return 1;int x=fp(a,b/2);x=(x*x)%mod;if(b&1) x=(x*a)%mod;return x;}

const int N=1e5+5;

const int mxA=2e5+5;

int prime[mxA]={0},last[mxA]={0};
int MAXN=sqrt(mxA);
vector<int> smlprime,large;

int a[N];

struct node
{
  int pw[86];
  vector<array<int,3>> v;
  node()
  {
    memset(pw,0,sizeof(pw));
  }
};
node merge(node a,node b,bool ok=true)
{
  node c;
  for(int i=0;i<smlprime.size();i++)
    c.pw[i]=max(a.pw[i],b.pw[i]);

  if(ok){

    int i=0;
    int j=0;

    while(i<a.v.size()&&j<b.v.size())
    {
      if(a.v[i][0]<b.v[j][0])
      {
        c.v.push_back(a.v[i]);
        i++;
      }
      else
      {
        c.v.push_back(b.v[j]);
        j++;
      }
    }
    while(i<a.v.size())
    {
        c.v.push_back(a.v[i]);
        i++;
    }
    while(j<b.v.size())
    {
        c.v.push_back(b.v[j]);
        j++;
    }
  }
  //  merge(a.v.begin(),a.v.end(),b.v.begin(),b.v.end(),c.v.begin());
  return c;
}

vector<node> bit(4*N);
void build(int id,int l,int r)
{
  if(l==r)
  {

      int x=a[l];

      while(x>1)
      {
        int p=prime[x],y=0;
        while(x%p==0)
          y++,x/=p;
        if(p<=MAXN)
        {
          int idx=lower_bound(smlprime.begin(),smlprime.end(),p)-smlprime.begin();
          bit[id].pw[idx]=y;
        }
        else
        {
         // cout<<p<<endl;
          bit[id].v.push_back({last[p],p,p});
          last[p]=l;
        }
      }
      return;
  }
  int mid=(l+r)/2;
  build(2*id,l,mid);
  build(2*id+1,mid+1,r);
  bit[id]=merge(bit[2*id],bit[2*id+1]);
  int x=1;
  for(auto &i:bit[id].v)
    i[2]=(i[1]*x)%mod,x=i[2];
}

int ans;

node get(int id,int l,int r,int L,int R)
{
  if(R<l||r<L){
    node c;
    return c;
  }
  if(L<=l&&r<=R)
  {

    // for(auto i:bit[id].v)
    //   cout<<i[0]<<" "<<i[1]<<" "<<i[2]<<endl;

  //  cout<<endl;
    int lw=0,hg=bit[id].v.size()-1;
    int r=1;
    if(bit[id].v.size())
    while(lw<=hg)
    {
      int mid=(lw+hg)/2;
      if(bit[id].v[mid][0]<L)
      {
        r=bit[id].v[mid][2];
        lw=mid+1;
      }
      else{
        hg=mid-1;
      }
    }
    ans=(ans*r)%mod;
    return bit[id];
  }
  int mid=(l+r)/2;
  return merge(get(2*id,l,mid,L,R),get(2*id+1,mid+1,r,L,R));
}

void upd(int id,int l,int r,int L,int R,int v)
{
  if(R<l||r<L)
    return;
  if(L<=l&&r<=R)
  {

    return;
  }
  int mid=(l+r)/2;
  upd(2*id,l,mid,L,R,v);
  upd(2*id+1,mid+1,r,L,R,v);
  bit[id]=merge(bit[2*id],bit[2*id+1]);
}

signed main() {
 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 prime[1]=1;
 for(int i=2;i<mxA;i++){
  if(prime[i]==0)
  {
    for(int j=1;j*i<mxA;j++)
      prime[j*i]=i;
    if(i<=MAXN)
      smlprime.push_back(i);
    else
      large.push_back(i);
  }
 }

// cout<<smlprime.size()<<endl;

 int n;
 cin>>n;
 for(int i=1;i<=n;i++)
 {
  cin>>a[i];
 }

 build(1,1,n);

 int q,last=0;
 cin>>q;
 while(q--)
 {
  int l,r;
  cin>>l>>r;

   l=(last+l)%n+1;
   r=(last+r)%n+1;
   if(l>r)
    swap(l,r);
 // cout<<l<<" "<<r<<endl;

  ans=1;
  node nd=get(1,1,n,l,r);
  for(int i=0;i<smlprime.size();i++)
  {
    ans=(ans*fp(smlprime[i],nd.pw[i]));
    if(ans>=mod)ans%=mod;
  }
  cout<<ans<<endl;
  last=ans;
 }

}


#include <bits/stdc++.h>
#include <random>

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define o cout<<"BUG"<<endl;
#define	IOS ios_base::sync_with_stdio(0);
#define en "\n"
#define FOR(i, j, n) for(int j = i; j < n; ++j)
#define forn(i, j, n) for(int j = i; j <= n; ++j)
#define nfor(i, j, n) for(int j = n; j >= i; --j)
#define sortv(vv) sort(vv.begin(), vv.end())
#define all(v) v.begin(), v.end()
#define ld long double
#define ull unsigned long long

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using namespace std;
const int maxn=2e5+100,LOG=20,mod=1e9+7;
ll block = 300, timer = 0;
const ld EPS = 1e-9;

#define bt(i) (1 << (i))
#define int ll
const ll inf = 1e18;
#define y1 yy
#define pii pair <int, int>

int n, t[4*maxn][100], a[maxn], q, last[maxn], ans, lp[maxn], pos[maxn], sz, temp[100];
vector <int> pr;
vector <int> tpref[4*maxn];
vector <pii> tval[4*maxn];

void build(int v, int tl, int tr)
{
	tpref[v].pb(1);
	tval[v].pb({0, 1});
	if(tl == tr)
	{
		while(a[tl] > 1)
		{
			int y = lp[a[tl]];
			int cnt = 0;
			while(lp[a[tl]] == y)
			{
				cnt++;
				a[tl] /= y;
			}
			if(y <= 499)
			{
				t[v][pos[y]] = cnt;
			}
			else
			{
				tpref[v].pb(last[y]);
				tval[v].pb({last[y], y});
				last[y] = tl;
			}
		}
		return;
	}
	build(v * 2, tl, (tl + tr) / 2);
	build(v * 2 + 1, (tl + tr) / 2 + 1, tr);
	forn(0, i, sz - 1)
	{
		t[v][i] = max(t[v * 2][i], t[v * 2 + 1][i]);
	}
	int uk1 = 0;
	int uk2 = 0;
	int F = v * 2;
	int S = v * 2 + 1;
	while(uk1 < tval[F].size() && uk2 < tval[S].size())
	{
		if(tval[F][uk1].f < tval[S][uk2].f)
		{
			tval[v].pb(tval[F][uk1++]);
		}
		else
		{
			tval[v].pb(tval[S][uk2++]);
		}
		tpref[v].pb(0);
	}
	while(uk1 < tval[F].size())
	{
		tval[v].pb(tval[F][uk1++]);
		tpref[v].pb(0);
	}
	while(uk2 < tval[S].size())
	{
		tval[v].pb(tval[S][uk2++]);
		tpref[v].pb(0);
	}
	FOR(1, i, tval[v].size())
	{
		tpref[v][i] = tpref[v][i - 1] * tval[v][i].s % mod;
	}
}

void get(int v, int tl, int tr, int l, int r)
{
	if(l <= tl && tr <= r)
	{
		int it = lower_bound(all(tval[v]), mp(l, 0ll)) - tval[v].begin() - 1;
		ans = ans * tpref[v][it] % mod;
		forn(0, i, sz - 1)
		{
			temp[i] = max(temp[i], t[v][i]);
		}
		return;
	}
	if(l > tr || r < tl) return;
	get(v * 2, tl, (tl + tr) / 2, l, r);
	get(v * 2 + 1, (tl + tr) / 2 + 1, tr, l, r);
}

inline int binpow(int a, int n)
{
	int res = 1;
	while(n)
	{
		if(n&1)
		{
			res = res * a % mod;
		}
		a = a * a % mod;
		n/=2;
	}
	return res;
}

main()
{
    IOS
	n = 200000;
	forn(2, i, n)
	{
		if(lp[i]) continue;
		if(i <= 499)
		{
			pos[i] = sz++;
			pr.pb(i);
		}
		for(int j = i; j <= n; j += i)
		{
			lp[j] = i;
		}
	}
	cin >> n;
	forn(1, i, n)
	{
		cin >> a[i];
	}
	build(1, 1, n);
	cin >> q;
	forn(1, it, q)
	{
		int l, r;
		cin >> l >> r;
		l = (ans + l) % n + 1;
		r = (ans + r) % n + 1;
		if(l > r) swap(l, r);
		ans = 1;
		get(1, 1, n, l, r);
		forn(0, i, sz - 1)
		{
			ans = ans * binpow(pr[i], temp[i]) % mod;
			temp[i] = 0;
		}
		cout << ans << "\n";
	}
}


#include <bits/stdc++.h>
#include <random>

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define o cout<<"BUG"<<endl;
#define	IOS ios_base::sync_with_stdio(0);
#define en "\n"
#define FOR(i, j, n) for(int j = i; j < n; ++j)
#define forn(i, j, n) for(int j = i; j <= n; ++j)
#define nfor(i, j, n) for(int j = n; j >= i; --j)
#define sortv(vv) sort(vv.begin(), vv.end())
#define all(v) v.begin(), v.end()
#define ld long double
#define ull unsigned long long

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using namespace std;
const int maxn=1e5+100,LOG=20,mod=1e9+7;
ll block = 300, timer = 0;
const ld EPS = 1e-9;

#define bt(i) (1 << (i))
#define int ll
const ll inf = 1e18;
#define y1 yy
#define pii pair <int, int>

int n, t[4*maxn][100], a[maxn], q, last[200100], ans, lp[200100], pos[600], sz, temp[100];
vector <int> pr;
vector <int> tpref[4*maxn];
vector <pii> tval[4*maxn];

void build(int v, int tl, int tr)
{
	if(tl == tr)
	{
		while(a[tl] > 1)
		{
			int y = lp[a[tl]];
			int cnt = 0;
			while(lp[a[tl]] == y)
			{
				cnt++;
				a[tl] /= y;
			}
			if(y <= 499)
			{
				t[v][pos[y]] = cnt;
			}
			else
			{
				tpref[v].pb(last[y]);
				tval[v].pb({last[y], y});
				last[y] = tl;
			}
		}
		return;
	}
	build(v * 2, tl, (tl + tr) / 2);
	build(v * 2 + 1, (tl + tr) / 2 + 1, tr);
	forn(0, i, sz - 1)
	{
		t[v][i] = max(t[v * 2][i], t[v * 2 + 1][i]);
	}
	int uk1 = 0;
	int uk2 = 0;
	int F = v * 2;
	int S = v * 2 + 1;
	while(uk1 < tval[F].size() && uk2 < tval[S].size())
	{
		if(tval[F][uk1].f < tval[S][uk2].f)
		{
			tval[v].pb(tval[F][uk1++]);
		}
		else
		{
			tval[v].pb(tval[S][uk2++]);
		}
		tpref[v].pb(0);
	}
	while(uk1 < tval[F].size())
	{
		tval[v].pb(tval[F][uk1++]);
		tpref[v].pb(0);
	}
	while(uk2 < tval[S].size())
	{
		tval[v].pb(tval[S][uk2++]);
		tpref[v].pb(0);
	}
	if(tval[v].size())
		tpref[v][0] = tval[v][0].s;
	FOR(1, i, tval[v].size())
	{
		tpref[v][i] = tpref[v][i - 1] * tval[v][i].s % mod;
	}
}

void get(int v, int tl, int tr, int l, int r)
{
	if(l <= tl && tr <= r)
	{
		int it = lower_bound(all(tval[v]), mp(l, 0ll)) - tval[v].begin() - 1;
		if(it >= 0)
		{
			ans = ans * tpref[v][it] % mod;
			if(tpref[v][it] == 0)
			{
				cout << "WH\n";
				exit(0);
			}
		}
		forn(0, i, sz - 1)
		{
			temp[i] = max(temp[i], t[v][i]);
		}
		return;
	}
	if(l > tr || r < tl) return;
	get(v * 2, tl, (tl + tr) / 2, l, r);
	get(v * 2 + 1, (tl + tr) / 2 + 1, tr, l, r);
}

inline int binpow(int a, int n)
{
	int res = 1;
	while(n)
	{
		if(n&1)
		{
			res = res * a % mod;
		}
		a = a * a % mod;
		n/=2;
	}
	return res;
}

main()
{
	IOS
	n = 200000;
	forn(2, i, n)
	{
		if(lp[i]) continue;
		if(i <= 499)
		{
			pos[i] = sz++;
			pr.pb(i);
		}
		for(int j = i; j <= n; j += i)
		{
			lp[j] = i;
		}
	}
	cin >> n;
	forn(1, i, n)
	{
		cin >> a[i];
	}
	build(1, 1, n);
	cin >> q;
	forn(1, it, q)
	{
		int l, r;
		cin >> l >> r;
		l = (ans + l) % n + 1;
		r = (ans + r) % n + 1;
		if(l > r) swap(l, r);
		ans = 1;
		get(1, 1, n, l, r);
		forn(0, i, sz - 1)
		{
			ans = ans * binpow(pr[i], temp[i]) % mod;
			if(ans == 0)
			{
				cout << "Here\n";
				return 0;
			}
			if(binpow(pr[i], temp[i]) == 0)
			{
				cout << "pr " << pr[i] << " " << temp[i];
				return 0;
			}
			temp[i] = 0;
		}
		cout << ans << "\n";
	}
}


#include <bits/stdc++.h>
#include <random>

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define o cout<<"BUG"<<endl;
#define	IOS ios_base::sync_with_stdio(0);
#define en "\n"
#define FOR(i, j, n) for(int j = i; j < n; ++j)
#define forn(i, j, n) for(int j = i; j <= n; ++j)
#define nfor(i, j, n) for(int j = n; j >= i; --j)
#define sortv(vv) sort(vv.begin(), vv.end())
#define all(v) v.begin(), v.end()
#define ld long double
#define ull unsigned long long

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using namespace std;
const int maxn=1e5+100,LOG=20,mod=1e9+7;
ll block = 300, timer = 0;
const ld EPS = 1e-9;

#define bt(i) (1 << (i))
#define int ll
const ll inf = 1e18;
#define y1 yy
#define pii pair <int, int>

int n, t[4*maxn][100], a[maxn], q, last[200100], ans, lp[200100], pos[600], sz, temp[100];
vector <int> pr;
vector <int> tpref[4*maxn];
vector <pii> tval[4*maxn];

void build(int v, int tl, int tr)
{
	tpref[v].pb(1);
	tval[v].pb({0, 1});
	if(tl == tr)
	{
		while(a[tl] > 1)
		{
			int y = lp[a[tl]];
			int cnt = 0;
			while(lp[a[tl]] == y)
			{
				cnt++;
				a[tl] /= y;
			}
			if(y <= 499)
			{
				t[v][pos[y]] = cnt;
			}
			else
			{
				tpref[v].pb(last[y]);
				tval[v].pb({last[y], y});
				last[y] = tl;
			}
		}
		return;
	}
	build(v * 2, tl, (tl + tr) / 2);
	build(v * 2 + 1, (tl + tr) / 2 + 1, tr);
	forn(0, i, sz - 1)
	{
		t[v][i] = max(t[v * 2][i], t[v * 2 + 1][i]);
	}
	int uk1 = 1;
	int uk2 = 1;
	int F = v * 2;
	int S = v * 2 + 1;
	while(uk1 < tval[F].size() && uk2 < tval[S].size())
	{
		if(tval[F][uk1].f < tval[S][uk2].f)
		{
			tval[v].pb(tval[F][uk1++]);
		}
		else
		{
			tval[v].pb(tval[S][uk2++]);
		}
		tpref[v].pb(0);
	}
	while(uk1 < tval[F].size())
	{
		tval[v].pb(tval[F][uk1++]);
		tpref[v].pb(0);
	}
	while(uk2 < tval[S].size())
	{
		tval[v].pb(tval[S][uk2++]);
		tpref[v].pb(0);
	}
	FOR(1, i, tval[v].size())
	{
		tpref[v][i] = tpref[v][i - 1] * tval[v][i].s % mod;
	}
}

void get(int v, int tl, int tr, int l, int r)
{
	if(l <= tl && tr <= r)
	{
		int it = lower_bound(all(tval[v]), mp(l, 0ll)) - tval[v].begin() - 1;
		ans = ans * tpref[v][it] % mod;
		forn(0, i, sz - 1)
		{
			temp[i] = max(temp[i], t[v][i]);
		}
		return;
	}
	if(l > tr || r < tl) return;
	get(v * 2, tl, (tl + tr) / 2, l, r);
	get(v * 2 + 1, (tl + tr) / 2 + 1, tr, l, r);
}

inline int binpow(int a, int n)
{
	int res = 1;
	while(n)
	{
		if(n&1)
		{
			res = res * a % mod;
		}
		a = a * a % mod;
		n/=2;
	}
	return res;
}

main()
{
	IOS
	n = 200000;
	forn(2, i, n)
	{
		if(lp[i]) continue;
		if(i <= 499)
		{
			pos[i] = sz++;
			pr.pb(i);
		}
		for(int j = i; j <= n; j += i)
		{
			lp[j] = i;
		}
	}
	cin >> n;
	forn(1, i, n)
	{
		cin >> a[i];
	}
	build(1, 1, n);
	cin >> q;
	forn(1, it, q)
	{
		int l, r;
		cin >> l >> r;
		l = (ans + l) % n + 1;
		r = (ans + r) % n + 1;
		if(l > r) swap(l, r);
		ans = 1;
		get(1, 1, n, l, r);
		forn(0, i, sz - 1)
		{
			ans = ans * binpow(pr[i], temp[i]) % mod;
			temp[i] = 0;
		}
		cout << ans << "\n";
	}
}


#include <bits/stdc++.h>
#include <random>

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define o cout<<"BUG"<<endl;
#define	IOS ios_base::sync_with_stdio(0);
#define en "\n"
#define FOR(i, j, n) for(int j = i; j < n; ++j)
#define forn(i, j, n) for(int j = i; j <= n; ++j)
#define nfor(i, j, n) for(int j = n; j >= i; --j)
#define sortv(vv) sort(vv.begin(), vv.end())
#define all(v) v.begin(), v.end()
#define ld long double
#define ull unsigned long long

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using namespace std;
const int maxn=1e5+100,LOG=20,mod=1e9+7;
ll block = 300, timer = 0;
const ld EPS = 1e-9;

#define bt(i) (1 << (i))
#define int ll
const ll inf = 1e18;
#define y1 yy
#define pii pair <int, int>

int n, t[4*maxn][100], a[maxn], q, last[200100], ans, lp[200100], pos[600], sz, temp[100];
vector <int> pr;
vector <int> tpref[4*maxn];
vector <pii> tval[4*maxn];

void build(int v, int tl, int tr)
{
	if(tl == tr)
	{
		while(a[tl] > 1)
		{
			int y = lp[a[tl]];
			int cnt = 0;
			while(lp[a[tl]] == y)
			{
				cnt++;
				a[tl] /= y;
			}
			if(y <= 499)
			{
				t[v][pos[y]] = cnt;
			}
			else
			{
				tpref[v].pb(last[y]);
				tval[v].pb({last[y], y});
				last[y] = tl;
			}
		}
		return;
	}
	build(v * 2, tl, (tl + tr) / 2);
	build(v * 2 + 1, (tl + tr) / 2 + 1, tr);
	forn(0, i, sz - 1)
	{
		t[v][i] = max(t[v * 2][i], t[v * 2 + 1][i]);
	}
	int uk1 = 0;
	int uk2 = 0;
	int F = v * 2;
	int S = v * 2 + 1;
	while(uk1 < tval[F].size() && uk2 < tval[S].size())
	{
		if(tval[F][uk1].f < tval[S][uk2].f)
		{
			tval[v].pb(tval[F][uk1++]);
		}
		else
		{
			tval[v].pb(tval[S][uk2++]);
		}
		tpref[v].pb(0);
	}
	while(uk1 < tval[F].size())
	{
		tval[v].pb(tval[F][uk1++]);
		tpref[v].pb(0);
	}
	while(uk2 < tval[S].size())
	{
		tval[v].pb(tval[S][uk2++]);
		tpref[v].pb(0);
	}
	if(tval[v].size())
		tpref[v][0] = tval[v][0].s;
	FOR(1, i, tval[v].size())
	{
		tpref[v][i] = tpref[v][i - 1] * tval[v][i].s % mod;
	}
}

void get(int v, int tl, int tr, int l, int r)
{
	if(l <= tl && tr <= r)
	{
		int it = lower_bound(all(tval[v]), mp(l, 0ll)) - tval[v].begin() - 1;
		if(it >= 0)
		{
			ans = ans * tpref[v][it] % mod;
			if(tpref[v][it] == 0)
			{
				cout << "WH\n";
				exit(0);
			}
		}
		forn(0, i, sz - 1)
		{
			temp[i] = max(temp[i], t[v][i]);
		}
		return;
	}
	if(l > tr || r < tl) return;
	get(v * 2, tl, (tl + tr) / 2, l, r);
	get(v * 2 + 1, (tl + tr) / 2 + 1, tr, l, r);
}

inline int binpow(int a, int n)
{
	int res = 1;
	while(n)
	{
		if(n&1)
		{
			res = res * a % mod;
		}
		a = a * a % mod;
		n/=2;
	}
	return res;
}

main()
{
	IOS
	n = 200000;
	forn(2, i, n)
	{
		if(lp[i]) continue;
		if(i <= 499)
		{
			pos[i] = sz++;
			pr.pb(i);
		}
		for(int j = i; j <= n; j += i)
		{
			lp[j] = i;
		}
	}
	cin >> n;
	forn(1, i, n)
	{
		cin >> a[i];
	}
	build(1, 1, n);
	cin >> q;
	forn(1, it, q)
	{
		int l, r;
		cin >> l >> r;
		l = (ans + l) % n + 1;
		r = (ans + r) % n + 1;
		if(l > r) swap(l, r);
		ans = 1;
		get(1, 1, n, l, r);
		forn(0, i, sz - 1)
		{
			ans = ans * binpow(pr[i], temp[i]) % mod;
			if(binpow(pr[i], temp[i]) == 0)
			{
				cout << "pr " << pr[i] << " " << temp[i];
				return 0;
			}
			temp[i] = 0;
		}
		cout << ans << "\n";
	}
}