#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(1);
	}
	while(uk1 < tval[F].size())
	{
		tval[v].pb(tval[F][uk1++]);
		tpref[v].pb(1);
	}
	while(uk2 < tval[S].size())
	{
		tval[v].pb(tval[S][uk2++]);
		tpref[v].pb(1);
	}
	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 m)
{
	int res = 1;
	while(m)
	{
		if(m&1)
		{
			res = res * a % mod;
		}
		a = a * a % mod;
		m/=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)
{
	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(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(1);
	}
	while(uk1 < tval[F].size())
	{
		tval[v].pb(tval[F][uk1++]);
		tpref[v].pb(1);
	}
	while(uk2 < tval[S].size())
	{
		tval[v].pb(tval[S][uk2++]);
		tpref[v].pb(1);
	}
	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 << tval[v][it].s << " " << tpref[v][it - 1] << endl;
				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 m)
{
	int res = 1;
	while(m)
	{
		if(m&1)
		{
			res = res * a % mod;
		}
		a = a * a % mod;
		m/=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 = 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)
{
	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(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(1);
	}
	while(uk1 < tval[F].size())
	{
		tval[v].pb(tval[F][uk1++]);
		tpref[v].pb(1);
	}
	while(uk2 < tval[S].size())
	{
		tval[v].pb(tval[S][uk2++]);
		tpref[v].pb(1);
	}
	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 << tval[v][it].s << " " << tpref[v][it - 1] << endl;
				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 m)
{
	int res = 1;
	while(m)
	{
		if(m&1)
		{
			res = res * a % mod;
		}
		a = a * a % mod;
		m/=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)
{
	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(1);
	}
	while(uk1 < tval[F].size())
	{
		tval[v].pb(tval[F][uk1++]);
		tpref[v].pb(1);
	}
	while(uk2 < tval[S].size())
	{
		tval[v].pb(tval[S][uk2++]);
		tpref[v].pb(1);
	}
	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)
{
	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";
				return 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";
	}
}


#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;
		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(1);
	}
	while(uk1 < tval[F].size())
	{
		tval[v].pb(tval[F][uk1++]);
		tpref[v].pb(1);
	}
	while(uk2 < tval[S].size())
	{
		tval[v].pb(tval[S][uk2++]);
		tpref[v].pb(1);
	}
	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 << tval[v][it].s << endl;
				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 m)
{
	int res = 1;
	while(m)
	{
		if(m&1)
		{
			res = res * a % mod;
		}
		a = a * a % mod;
		m/=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)
{
	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(1);
	}
	while(uk1 < tval[F].size())
	{
		tval[v].pb(tval[F][uk1++]);
		tpref[v].pb(1);
	}
	while(uk2 < tval[S].size())
	{
		tval[v].pb(tval[S][uk2++]);
		tpref[v].pb(1);
	}
	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 << tval[v][it] << endl;
				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 m)
{
	int res = 1;
	while(m)
	{
		if(m&1)
		{
			res = res * a % mod;
		}
		a = a * a % mod;
		m/=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(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>
#define f first
#define s second
#define pb push_back
#define pii pair<int, int>
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vvl vector<vl>
#define vld vector<ld>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define vpll vector<pll>
#define rep(s, l, r) for (int s = l; s < r; s++)
#define per(s, r, l) for (int s = r - 1; s >= l; s--)
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef long double ld;
using namespace std;
template<class T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> void setmax(T& a, T b) { a = max(a, b); };
template<typename T> void setmin(T& a, T b) { a = min(a, b); };
template<typename T> bool in(T lo, T v, T hi) { return lo <= v && v <= hi; };

template<ll MOD>
struct ModInt {
  ll x = 0;
  ModInt() { x = 0; }
  ModInt(ll _x) {
    x = _x;
    if (x >= MOD || x <= -MOD) x %= MOD;
    if (x < 0) x += MOD;
  }
  friend ModInt operator+(ModInt a, ModInt b) {
    return ModInt(a.x + b.x);
  }
  friend ModInt operator-(ModInt a, ModInt b) {
    return ModInt(a.x - b.x);
  }
  friend ModInt operator*(ModInt a, ModInt b) {
    return ModInt(a.x * b.x);
  }
  friend ModInt operator/(ModInt a, ModInt b) {
    return a * inv(b);
  }
  friend ModInt power(ModInt a, ll b) {
    if (b == 0) return 1;
    ModInt c = power(a, b / 2);
    return c * c * ((b & 1) ? a : 1);
  }
  friend ModInt inv(ModInt a) {
    // this only works for nonzero elements
    return power(a, MOD - 2);
  }
  friend ostream& operator<<(ostream &os, const ModInt a) {
    os << a.x;
    return os;
  }
};

using mint = ModInt<1000000007>;

const int N = 1e5 + 10;
const int R = 318;
int n;
vi primes; // <= sqrt

void sieve() {
  vi pr(R, 1);
  for (int i = 2; i < R; i++) {
    if (pr[i]) {
      primes.pb(i);
      for (int j = 2 * i; j < R; j += i) pr[j] = false;
    }
  }
}

struct small {
  vector<map<int, int>> tree;
  vi a;
  small(vi _a) {
    a = _a;
    tree.resize(4 * n);
    build(0, 0, n - 1);
  }
  map<int, int> merge(map<int, int> a, map<int, int> b) {
    map<int, int> c;
    for (auto& [p, e] : a) c[p] = e;
    for (auto& [p, e] : b) setmax(c[p], e);
    return c;
  }
  void build(int node, int lo, int hi) {
    if (lo == hi) {
      for (int pr : primes) {
        int aa = a[lo];
        while (aa % pr == 0) {
          tree[node][pr]++; aa /= pr;
        }
      }
    } else {
      int mid = (lo + hi) / 2;
      build(2 * node + 1, lo, mid);
      build(2 * node + 2, mid + 1, hi);
      tree[node] = merge(tree[2 * node + 1], tree[2 * node + 2]);
    }
  }
  map<int, int> get(int node, int lo, int hi, int l, int r) {
    if (r < lo || hi < l) {
      return {};
    }
    if (l <= lo && hi <= r) {
      return tree[node];
    }
    int mid = (lo + hi) / 2;
    return merge(get(2 * node + 1, lo, mid, l, r), get(2 * node + 2, mid + 1, hi, l, r));
  }
  mint query(int lo, int hi) {
    map<int, int> m = get(0, 0, n - 1, lo, hi);
    mint res = 1;
    for (auto &[p, e] : m) {
      res = res * power(mint(p), e);
    }
    return res;
  }
};

struct big {
  vvpii tree;
  vector<vector<mint>> prod;
  vi a;
  vi prev;
  big(vi _a) {
    a = _a;
    prev.assign(n, -1);
    map<int, int> p;
    rep(i, 0, n) {
      prev[i] = p.count(a[i]) ? p[a[i]] : -1;
      p[a[i]] = i;
    }
    tree.resize(4 * n);
    prod.resize(4 * n);
    build(0, 0, n - 1);
  }
  void build(int node, int lo, int hi) {
    if (lo == hi) {
      tree[node] = {{prev[lo], a[lo]}};
    } else {
      for (auto x : tree[2 * node + 1]) tree[node].pb(x);
      for (auto x : tree[2 * node + 2]) tree[node].pb(x);
      sort(all(tree[node]));
      mint p = 1;
      for (auto x : tree[node]) {
        p = p * mint(x.s);
        prod[node].pb(p);
      }
    }
  }
  mint get(int node, int lo, int hi, int l, int r) {
    if (r < lo || hi < l) return 1;
    if (l <= lo && hi <= r) {
      int i = 0, j = tree[node].size() - 1, ans = -1;
      while (i <= j) {
        int m = (i + j) / 2;
        if (tree[node][m].f < l) {
          ans = m;
          i = m + 1;
        } else {
          j = m - 1;
        }
      }
      return ans == -1 ? 1 : prod[node][ans];
    }
    int mid = (lo + hi) / 2;
    return get(2 * node + 1, lo, mid, l, r) * get(2 * node + 2, mid + 1, hi, l, r);
  }
  mint query(int lo, int hi) {
    return get(0, 0, n - 1, lo, hi);
  }
};

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  sieve();

  cin >> n;
  vi a(n);
  rep(i, 0, n) cin >> a[i];
  vi u(n, 1);
  rep(i, 0, n) {
    for (int pr : primes) {
      while (a[i] % pr == 0) {
        a[i] /= pr;
        u[i] *= pr;
      }
    }
  }

  small s(u);
  big b(a);

  int last = 0;
  int q;
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    int l = (last + x) % n;
    int r = (last + y) % n;
    if (l > r) swap(l, r);
//    cout << "~~ " << l << " " << r << endl;
    mint cur = s.query(l, r) * b.query(l, r);
    cout << cur  << endl;
    last = cur.x;
  }

  return 0;
}


#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define pii pair<int, int>
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vvl vector<vl>
#define vld vector<ld>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define vpll vector<pll>
#define rep(s, l, r) for (int s = l; s < r; s++)
#define per(s, r, l) for (int s = r - 1; s >= l; s--)
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef long double ld;
using namespace std;
template<class T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> void setmax(T& a, T b) { a = max(a, b); };
template<typename T> void setmin(T& a, T b) { a = min(a, b); };
template<typename T> bool in(T lo, T v, T hi) { return lo <= v && v <= hi; };

template<ll MOD>
struct ModInt {
  ll x = 0;
  ModInt() { x = 0; }
  ModInt(ll _x) {
    x = _x;
    if (x >= MOD || x <= -MOD) x %= MOD;
    if (x < 0) x += MOD;
  }
  friend ModInt operator+(ModInt a, ModInt b) {
    return ModInt(a.x + b.x);
  }
  friend ModInt operator-(ModInt a, ModInt b) {
    return ModInt(a.x - b.x);
  }
  friend ModInt operator*(ModInt a, ModInt b) {
    return ModInt(a.x * b.x);
  }
  friend ModInt operator/(ModInt a, ModInt b) {
    return a * inv(b);
  }
  friend ModInt power(ModInt a, ll b) {
    if (b == 0) return 1;
    ModInt c = power(a, b / 2);
    return c * c * ((b & 1) ? a : 1);
  }
  friend ModInt inv(ModInt a) {
    // this only works for nonzero elements
    return power(a, MOD - 2);
  }
  friend ostream& operator<<(ostream &os, const ModInt a) {
    os << a.x;
    return os;
  }
};

using mint = ModInt<1000000007>;

const int N = 1e5 + 10;
const int R = 450;
int n;
vi primes; // <= sqrt

void sieve() {
  vi pr(R, 1);
  for (int i = 2; i < R; i++) {
    if (pr[i]) {
      primes.pb(i);
      for (int j = 2 * i; j < R; j += i)
        pr[j] = 0;
    }
  }
}

struct small {
  vector<map<int, int>> tree;
  vi a;
  small(vi _a) {
    a = _a;
    tree.resize(4 * n);
    build(0, 0, n - 1);
  }
  map<int, int> merge(map<int, int> a, map<int, int> b) {
    map<int, int> c;
    for (auto& [p, e] : a) c[p] = e;
    for (auto& [p, e] : b) setmax(c[p], e);
    return c;
  }
  void build(int node, int lo, int hi) {
    if (lo == hi) {
      for (int pr : primes) {
        int aa = a[lo];
        while (aa % pr == 0) {
          tree[node][pr]++; aa /= pr;
        }
      }
    } else {
      int mid = (lo + hi) / 2;
      build(2 * node + 1, lo, mid);
      build(2 * node + 2, mid + 1, hi);
      tree[node] = merge(tree[2 * node + 1], tree[2 * node + 2]);
    }
  }
  map<int, int> get(int node, int lo, int hi, int l, int r) {
    if (r < lo || hi < l) {
      return {};
    }
    if (l <= lo && hi <= r) {
      return tree[node];
    }
    int mid = (lo + hi) / 2;
    return merge(get(2 * node + 1, lo, mid, l, r), get(2 * node + 2, mid + 1, hi, l, r));
  }
  mint query(int lo, int hi) {
    map<int, int> m = get(0, 0, n - 1, lo, hi);
    mint res = 1;
    for (auto &[p, e] : m) {
      res = res * power(mint(p), e);
    }
    return res;
  }
};

struct big {
  vvpii tree;
  vector<vector<mint>> prod;
  vi a;
  vi prev;
  big(vi _a) {
    a = _a;
    prev.assign(n, -1);
    map<int, int> p;
    rep(i, 0, n) {
      prev[i] = p.count(a[i]) ? p[a[i]] : -1;
      p[a[i]] = i;
    }
    tree.resize(4 * n);
    prod.resize(4 * n);
    build(0, 0, n - 1);
  }
  void build(int node, int lo, int hi) {
    if (lo == hi) {
      tree[node] = {{prev[lo], a[lo]}};
      prod[node] = { a[lo] };
    } else {
      int mid = (lo + hi) / 2;
      build(2 * node + 1, lo, mid);
      build(2 * node + 2, mid + 1, hi);
      for (auto x : tree[2 * node + 1]) tree[node].pb(x);
      for (auto x : tree[2 * node + 2]) tree[node].pb(x);
      sort(all(tree[node]));
      mint p = 1;
      for (auto x : tree[node]) {
        p = p * mint(x.s);
        prod[node].pb(p);
      }
    }
  }
  mint get(int node, int lo, int hi, int l, int r) {
    if (r < lo || hi < l) return 1;
    if (l <= lo && hi <= r) {
      int cnt = lower_bound(all(tree[node]), make_pair(l + 1, 0)) - tree[node].begin();
      mint res = cnt == 0 ? 1 : prod[node][cnt - 1];
      return res;
    }
    int mid = (lo + hi) / 2;
    return get(2 * node + 1, lo, mid, l, r) * get(2 * node + 2, mid + 1, hi, l, r);
  }
  mint query(int lo, int hi) {
    return get(0, 0, n - 1, lo, hi);
  }
};

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  sieve();

  cin >> n;
  vi a(n);
  rep(i, 0, n) cin >> a[i];
  vi u(n, 1);
  rep(i, 0, n) {
    for (int pr : primes) {
      while (a[i] % pr == 0) {
        a[i] /= pr;
        u[i] *= pr;
      }
    }
  }

  small s(u);
  big b(a);

  ll last = 0;
  int q;
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    int l = (last + x) % n;
    int r = (last + y) % n;
    if (l > r) swap(l, r);
//    cout << "~~ " << l << " " << r << endl;
//    cout << s.query(l, r) << endl;
//    cout << b.query(l, r) << endl;
    mint cur = s.query(l, r) * b.query(l, r);
    cout << cur  << endl;
    last = cur.x;
  }

  return 0;
}


#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define pii pair<int, int>
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vvl vector<vl>
#define vld vector<ld>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define vpll vector<pll>
#define rep(s, l, r) for (int s = l; s < r; s++)
#define per(s, r, l) for (int s = r - 1; s >= l; s--)
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef long double ld;
using namespace std;
template<class T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> void setmax(T& a, T b) { a = max(a, b); };
template<typename T> void setmin(T& a, T b) { a = min(a, b); };
template<typename T> bool in(T lo, T v, T hi) { return lo <= v && v <= hi; };

template<ll MOD>
struct ModInt {
  ll x = 0;
  ModInt() { x = 0; }
  ModInt(ll _x) {
    x = _x;
    if (x >= MOD || x <= -MOD) x %= MOD;
    if (x < 0) x += MOD;
  }
  friend ModInt operator+(ModInt a, ModInt b) {
    return ModInt(a.x + b.x);
  }
  friend ModInt operator-(ModInt a, ModInt b) {
    return ModInt(a.x - b.x);
  }
  friend ModInt operator*(ModInt a, ModInt b) {
    return ModInt(a.x * b.x);
  }
  friend ModInt operator/(ModInt a, ModInt b) {
    return a * inv(b);
  }
  friend ModInt power(ModInt a, ll b) {
    if (b == 0) return 1;
    ModInt c = power(a, b / 2);
    return c * c * ((b & 1) ? a : 1);
  }
  friend ModInt inv(ModInt a) {
    // this only works for nonzero elements
    return power(a, MOD - 2);
  }
  friend ostream& operator<<(ostream &os, const ModInt a) {
    os << a.x;
    return os;
  }
};

using mint = ModInt<1000000007>;

const int N = 1e5 + 10;
const int R = 450;
int n;
vi primes; // <= sqrt

void sieve() {
  vi pr(R, 1);
  for (int i = 2; i < R; i++) {
    if (pr[i]) {
      primes.pb(i);
      for (int j = 2 * i; j < R; j += i)
        pr[j] = 0;
    }
  }
}

struct small {
  vector<map<int, int>> tree;
  vi a;
  small(vi _a) {
    a = _a;
    tree.resize(4 * n);
    build(0, 0, n - 1);
  }
  map<int, int> merge(map<int, int> a, map<int, int> b) {
    map<int, int> c;
    for (auto& [p, e] : a) c[p] = e;
    for (auto& [p, e] : b) setmax(c[p], e);
    return c;
  }
  void build(int node, int lo, int hi) {
    if (lo == hi) {
      for (int pr : primes) {
        int aa = a[lo];
        while (aa % pr == 0) {
          tree[node][pr]++; aa /= pr;
        }
      }
    } else {
      int mid = (lo + hi) / 2;
      build(2 * node + 1, lo, mid);
      build(2 * node + 2, mid + 1, hi);
      tree[node] = merge(tree[2 * node + 1], tree[2 * node + 2]);
    }
  }
  map<int, int> get(int node, int lo, int hi, int l, int r) {
    if (r < lo || hi < l) {
      return {};
    }
    if (l <= lo && hi <= r) {
      return tree[node];
    }
    int mid = (lo + hi) / 2;
    return merge(get(2 * node + 1, lo, mid, l, r), get(2 * node + 2, mid + 1, hi, l, r));
  }
  mint query(int lo, int hi) {
    map<int, int> m = get(0, 0, n - 1, lo, hi);
    mint res = 1;
    for (auto &[p, e] : m) {
      res = res * power(mint(p), e);
    }
    return res;
  }
};

struct big {
  vvpii tree;
  vector<vector<mint>> prod;
  vi a;
  vi prev;
  big(vi _a) {
    a = _a;
    prev.assign(n, -1);
    map<int, int> p;
    rep(i, 0, n) {
      prev[i] = p.count(a[i]) ? p[a[i]] : -1;
      p[a[i]] = i;
    }
    tree.resize(4 * n);
    prod.resize(4 * n);
    build(0, 0, n - 1);
  }
  void build(int node, int lo, int hi) {
    if (lo == hi) {
      tree[node] = {{prev[lo], a[lo]}};
      prod[node] = { a[lo] };
    } else {
      int mid = (lo + hi) / 2;
      build(2 * node + 1, lo, mid);
      build(2 * node + 2, mid + 1, hi);
      for (auto x : tree[2 * node + 1]) tree[node].pb(x);
      for (auto x : tree[2 * node + 2]) tree[node].pb(x);
      sort(all(tree[node]));
      mint p = 1;
      for (auto x : tree[node]) {
        p = p * mint(x.s);
        prod[node].pb(p);
      }
    }
  }
  mint get(int node, int lo, int hi, int l, int r) {
    if (r < lo || hi < l) return 1;
    if (l <= lo && hi <= r) {
      int cnt = lower_bound(all(tree[node]), make_pair(l, 0)) - tree[node].begin();
      mint res = cnt == 0 ? 1 : prod[node][cnt - 1];
      return res;
    }
    int mid = (lo + hi) / 2;
    return get(2 * node + 1, lo, mid, l, r) * get(2 * node + 2, mid + 1, hi, l, r);
  }
  mint query(int lo, int hi) {
    return get(0, 0, n - 1, lo, hi);
  }
};

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  sieve();

  cin >> n;
  vi a(n);
  rep(i, 0, n) cin >> a[i];
  vi u(n, 1);
  rep(i, 0, n) {
    for (int pr : primes) {
      while (a[i] % pr == 0) {
        a[i] /= pr;
        u[i] *= pr;
      }
    }
  }

  small s(u);
  big b(a);

  ll last = 0;
  int q;
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    int l = (last + x) % n;
    int r = (last + y) % n;
    if (l > r) swap(l, r);
//    cout << "~~ " << l << " " << r << endl;
//    cout << s.query(l, r) << endl;
//    cout << b.query(l, r) << endl;
    mint cur = s.query(l, r) * b.query(l, r);
    cout << cur  << endl;
    last = cur.x;
  }

  return 0;
}


#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define pii pair<int, int>
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vvl vector<vl>
#define vld vector<ld>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define vpll vector<pll>
#define rep(s, l, r) for (int s = l; s < r; s++)
#define per(s, r, l) for (int s = r - 1; s >= l; s--)
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef long double ld;
using namespace std;
template<class T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> void setmax(T& a, T b) { a = max(a, b); };
template<typename T> void setmin(T& a, T b) { a = min(a, b); };
template<typename T> bool in(T lo, T v, T hi) { return lo <= v && v <= hi; };

template<ll MOD>
struct ModInt {
  ll x = 0;
  ModInt() { x = 0; }
  ModInt(ll _x) {
    x = _x;
    if (x >= MOD || x <= -MOD) x %= MOD;
    if (x < 0) x += MOD;
  }
  friend ModInt operator+(ModInt a, ModInt b) {
    return ModInt(a.x + b.x);
  }
  friend ModInt operator-(ModInt a, ModInt b) {
    return ModInt(a.x - b.x);
  }
  friend ModInt operator*(ModInt a, ModInt b) {
    return ModInt(a.x * b.x);
  }
  friend ModInt operator/(ModInt a, ModInt b) {
    return a * inv(b);
  }
  friend ModInt power(ModInt a, ll b) {
    if (b == 0) return 1;
    ModInt c = power(a, b / 2);
    return c * c * ((b & 1) ? a : 1);
  }
  friend ModInt inv(ModInt a) {
    // this only works for nonzero elements
    return power(a, MOD - 2);
  }
  friend ostream& operator<<(ostream &os, const ModInt a) {
    os << a.x;
    return os;
  }
};

using mint = ModInt<1000000007>;

const int N = 1e5 + 10;
const int R = 318;
int n;
vi primes; // <= sqrt

void sieve() {
  vi pr(R, 1);
  for (int i = 2; i < R; i++) {
    if (pr[i]) {
      primes.pb(i);
      for (int j = 2 * i; j < R; j += i) pr[j] = false;
    }
  }
}

struct small {
  vector<map<int, int>> tree;
  vi a;
  small(vi _a) {
    a = _a;
    tree.resize(4 * n);
    build(0, 0, n - 1);
  }
  map<int, int> merge(map<int, int> a, map<int, int> b) {
    map<int, int> c;
    for (auto& [p, e] : a) c[p] = e;
    for (auto& [p, e] : b) setmax(c[p], e);
    return c;
  }
  void build(int node, int lo, int hi) {
    if (lo == hi) {
      for (int pr : primes) {
        int aa = a[lo];
        while (aa % pr == 0) {
          tree[node][pr]++; aa /= pr;
        }
      }
    } else {
      int mid = (lo + hi) / 2;
      build(2 * node + 1, lo, mid);
      build(2 * node + 2, mid + 1, hi);
      tree[node] = merge(tree[2 * node + 1], tree[2 * node + 2]);
    }
  }
  map<int, int> get(int node, int lo, int hi, int l, int r) {
    if (r < lo || hi < l) {
      return {};
    }
    if (l <= lo && hi <= r) {
      return tree[node];
    }
    int mid = (lo + hi) / 2;
    return merge(get(2 * node + 1, lo, mid, l, r), get(2 * node + 2, mid + 1, hi, l, r));
  }
  mint query(int lo, int hi) {
    map<int, int> m = get(0, 0, n - 1, lo, hi);
    mint res = 1;
    for (auto &[p, e] : m) {
      res = res * power(mint(p), e);
    }
    return res;
  }
};

struct big {
  vvpii tree;
  vector<vector<mint>> prod;
  vi a;
  vi prev;
  big(vi _a) {
    a = _a;
    prev.assign(n, -1);
    map<int, int> p;
    rep(i, 0, n) {
      prev[i] = p.count(a[i]) ? p[a[i]] : -1;
      p[a[i]] = i;
    }
    tree.resize(4 * n);
    prod.resize(4 * n);
    build(0, 0, n - 1);
  }
  void build(int node, int lo, int hi) {
    if (lo == hi) {
      tree[node] = {{prev[lo], a[lo]}};
      prod[node] = { a[lo] };
    } else {
      int mid = (lo + hi) / 2;
      build(2 * node + 1, lo, mid);
      build(2 * node + 2, mid + 1, hi);
      for (auto x : tree[2 * node + 1]) tree[node].pb(x);
      for (auto x : tree[2 * node + 2]) tree[node].pb(x);
      sort(all(tree[node]));
      mint p = 1;
      for (auto x : tree[node]) {
        p = p * mint(x.s);
        prod[node].pb(p);
      }
    }
  }
  mint get(int node, int lo, int hi, int l, int r) {
    if (r < lo || hi < l) return 1;
    if (l <= lo && hi <= r) {
      int cnt = lower_bound(all(tree[node]), make_pair(l + 1, 0)) - tree[node].begin();
      mint res = cnt == 0 ? 1 : prod[node][cnt - 1];
      return res;
    }
    int mid = (lo + hi) / 2;
    return get(2 * node + 1, lo, mid, l, r) * get(2 * node + 2, mid + 1, hi, l, r);
  }
  mint query(int lo, int hi) {
    mint v = get(0, 0, n - 1, lo, hi);
    return v;
  }
};

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  sieve();

  cin >> n;
  vi a(n);
  rep(i, 0, n) cin >> a[i];
  vi u(n, 1);
  rep(i, 0, n) {
    for (int pr : primes) {
      while (a[i] % pr == 0) {
        a[i] /= pr;
        u[i] *= pr;
      }
    }
  }

  small s(u);
  big b(a);

  int last = 0;
  int q;
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    int l = (last + x) % n;
    int r = (last + y) % n;
    if (l > r) swap(l, r);
//    cout << "~~ " << l << " " << r << endl;
    mint cur = s.query(l, r) * b.query(l, r);
    cout << cur  << endl;
    last = cur.x;
  }

  return 0;
}


#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define pii pair<int, int>
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vvl vector<vl>
#define vld vector<ld>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define vpll vector<pll>
#define rep(s, l, r) for (int s = l; s < r; s++)
#define per(s, r, l) for (int s = r - 1; s >= l; s--)
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef long double ld;
using namespace std;
template<class T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> void setmax(T& a, T b) { a = max(a, b); };
template<typename T> void setmin(T& a, T b) { a = min(a, b); };
template<typename T> bool in(T lo, T v, T hi) { return lo <= v && v <= hi; };

template<ll MOD>
struct ModInt {
  ll x = 0;
  ModInt() { x = 0; }
  ModInt(ll _x) {
    x = _x;
    if (x >= MOD || x <= -MOD) x %= MOD;
    if (x < 0) x += MOD;
  }
  friend ModInt operator+(ModInt a, ModInt b) {
    return ModInt(a.x + b.x);
  }
  friend ModInt operator-(ModInt a, ModInt b) {
    return ModInt(a.x - b.x);
  }
  friend ModInt operator*(ModInt a, ModInt b) {
    return ModInt(a.x * b.x);
  }
  friend ModInt operator/(ModInt a, ModInt b) {
    return a * inv(b);
  }
  friend ModInt power(ModInt a, ll b) {
    if (b == 0) return 1;
    ModInt c = power(a, b / 2);
    return c * c * ((b & 1) ? a : 1);
  }
  friend ModInt inv(ModInt a) {
    // this only works for nonzero elements
    return power(a, MOD - 2);
  }
  friend ostream& operator<<(ostream &os, const ModInt a) {
    os << a.x;
    return os;
  }
};

using mint = ModInt<1000000007>;

const int N = 1e5 + 10;
const int R = 450;
int PI;
int n;
vi primes; // <= sqrt

void sieve() {
  vi pr(R, 1);
  for (int i = 2; i < R; i++) {
    if (pr[i]) {
      primes.pb(i);
      for (int j = 2 * i; j < R; j += i)
        pr[j] = 0;
    }
  }
  PI = primes.size();
}

struct small {
  vvi tree;
  vi a;
  small(vi _a) {
    a = _a;
    tree.assign(4 * n, vi(PI, 0));
    build(0, 0, n - 1);
  }
  vi merge(vi a, vi b) {
    vi c(PI, 0);
    rep(i, 0, PI) c[i] = max(a[i], b[i]);
    return c;
  }
  void build(int node, int lo, int hi) {
    if (lo == hi) {
      rep(i, 0, PI) {
        int aa = a[lo];
        while (aa % primes[i] == 0) {
          aa /= primes[i];
          tree[node][i]++;
        }
      }
    } else {
      int mid = (lo + hi) / 2;
      build(2 * node + 1, lo, mid);
      build(2 * node + 2, mid + 1, hi);
      tree[node] = merge(tree[2 * node + 1], tree[2 * node + 2]);
    }
  }
  vi get(int node, int lo, int hi, int l, int r) {
    if (r < lo || hi < l) {
      return vi(PI, 0);
    }
    if (l <= lo && hi <= r) {
      return tree[node];
    }
    int mid = (lo + hi) / 2;
    return merge(get(2 * node + 1, lo, mid, l, r), get(2 * node + 2, mid + 1, hi, l, r));
  }
  mint query(int lo, int hi) {
    vi e = get(0, 0, n - 1, lo, hi);
    mint res = 1;
    rep(i, 0, PI) {
      res = res * power(mint(primes[i]), e[i]);
    }
    return res;
  }
};

struct big {
  vvpii tree;
  vector<vector<mint>> prod;
  vi a;
  vi prev;
  big(vi _a) {
    a = _a;
    prev.assign(n, -1);
    map<int, int> p;
    rep(i, 0, n) {
      prev[i] = p.count(a[i]) ? p[a[i]] : -1;
      p[a[i]] = i;
    }
    tree.resize(4 * n);
    prod.resize(4 * n);
    build(0, 0, n - 1);
  }
  void build(int node, int lo, int hi) {
    if (lo == hi) {
      tree[node] = {{prev[lo], a[lo]}};
      prod[node] = { a[lo] };
    } else {
      int mid = (lo + hi) / 2;
      build(2 * node + 1, lo, mid);
      build(2 * node + 2, mid + 1, hi);
      for (auto x : tree[2 * node + 1]) tree[node].pb(x);
      for (auto x : tree[2 * node + 2]) tree[node].pb(x);
      sort(all(tree[node]));
      mint p = 1;
      for (auto x : tree[node]) {
        p = p * mint(x.s);
        prod[node].pb(p);
      }
    }
  }
  mint get(int node, int lo, int hi, int l, int r) {
    if (r < lo || hi < l) return 1;
    if (l <= lo && hi <= r) {
      int cnt = lower_bound(all(tree[node]), make_pair(l, 0)) - tree[node].begin();
      mint res = cnt == 0 ? 1 : prod[node][cnt - 1];
      return res;
    }
    int mid = (lo + hi) / 2;
    return get(2 * node + 1, lo, mid, l, r) * get(2 * node + 2, mid + 1, hi, l, r);
  }
  mint query(int lo, int hi) {
    return get(0, 0, n - 1, lo, hi);
  }
};

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  sieve();

  cin >> n;
  vi a(n);
  rep(i, 0, n) cin >> a[i];
  vi u(n, 1);
  rep(i, 0, n) {
    for (int pr : primes) {
      while (a[i] % pr == 0) {
        a[i] /= pr;
        u[i] *= pr;
      }
    }
  }

  small s(u);
  big b(a);

  ll last = 0;
  int q;
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    int l = (last + x) % n;
    int r = (last + y) % n;
    if (l > r) swap(l, r);
//    cout << "~~ " << l << " " << r << endl;
//    cout << s.query(l, r) << endl;
//    cout << b.query(l, r) << endl;
    mint cur = s.query(l, r) * b.query(l, r);
    cout << cur  << endl;
    last = cur.x;
  }

  return 0;
}


#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define pii pair<int, int>
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vvl vector<vl>
#define vld vector<ld>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define vpll vector<pll>
#define rep(s, l, r) for (int s = l; s < r; s++)
#define per(s, r, l) for (int s = r - 1; s >= l; s--)
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef long double ld;
using namespace std;
template<class T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> void setmax(T& a, T b) { a = max(a, b); };
template<typename T> void setmin(T& a, T b) { a = min(a, b); };
template<typename T> bool in(T lo, T v, T hi) { return lo <= v && v <= hi; };

template<ll MOD>
struct ModInt {
  ll x = 0;
  ModInt() { x = 0; }
  ModInt(ll _x) {
    x = _x;
    if (x >= MOD || x <= -MOD) x %= MOD;
    if (x < 0) x += MOD;
  }
  friend ModInt operator+(ModInt a, ModInt b) {
    return ModInt(a.x + b.x);
  }
  friend ModInt operator-(ModInt a, ModInt b) {
    return ModInt(a.x - b.x);
  }
  friend ModInt operator*(ModInt a, ModInt b) {
    return ModInt(a.x * b.x);
  }
  friend ModInt operator/(ModInt a, ModInt b) {
    return a * inv(b);
  }
  friend ModInt power(ModInt a, ll b) {
    if (b == 0) return 1;
    ModInt c = power(a, b / 2);
    return c * c * ((b & 1) ? a : 1);
  }
  friend ModInt inv(ModInt a) {
    // this only works for nonzero elements
    return power(a, MOD - 2);
  }
  friend ostream& operator<<(ostream &os, const ModInt a) {
    os << a.x;
    return os;
  }
};

using mint = ModInt<1000000007>;

const int N = 1e5 + 10;
const int R = 318;
int n;
vi primes; // <= sqrt

void sieve() {
  vi pr(R, 1);
  for (int i = 2; i < R; i++) {
    if (pr[i]) {
      primes.pb(i);
      for (int j = 2 * i; j < R; j += i) pr[j] = false;
    }
  }
}

struct small {
  vector<map<int, int>> tree;
  vi a;
  small(vi _a) {
    a = _a;
    tree.resize(4 * n);
    build(0, 0, n - 1);
  }
  map<int, int> merge(map<int, int> a, map<int, int> b) {
    map<int, int> c;
    for (auto& [p, e] : a) c[p] = e;
    for (auto& [p, e] : b) setmax(c[p], e);
    return c;
  }
  void build(int node, int lo, int hi) {
    if (lo == hi) {
      for (int pr : primes) {
        int aa = a[lo];
        while (aa % pr == 0) {
          tree[node][pr]++; aa /= pr;
        }
      }
    } else {
      int mid = (lo + hi) / 2;
      build(2 * node + 1, lo, mid);
      build(2 * node + 2, mid + 1, hi);
      tree[node] = merge(tree[2 * node + 1], tree[2 * node + 2]);
    }
  }
  map<int, int> get(int node, int lo, int hi, int l, int r) {
    if (r < lo || hi < l) {
      return {};
    }
    if (l <= lo && hi <= r) {
      return tree[node];
    }
    int mid = (lo + hi) / 2;
    return merge(get(2 * node + 1, lo, mid, l, r), get(2 * node + 2, mid + 1, hi, l, r));
  }
  mint query(int lo, int hi) {
    map<int, int> m = get(0, 0, n - 1, lo, hi);
    mint res = 1;
    for (auto &[p, e] : m) {
      res = res * power(mint(p), e);
    }
    return res;
  }
};

struct big {
  vvpii tree;
  vector<vector<mint>> prod;
  vi a;
  vi prev;
  big(vi _a) {
    a = _a;
    prev.assign(n, -1);
    map<int, int> p;
    rep(i, 0, n) {
      prev[i] = p.count(a[i]) ? p[a[i]] : -1;
      p[a[i]] = i;
    }
    tree.resize(4 * n);
    prod.resize(4 * n);
    build(0, 0, n - 1);
  }
  void build(int node, int lo, int hi) {
    if (lo == hi) {
      tree[node] = {{prev[lo], a[lo]}};
      prod[node] = { a[lo] };
    } else {
      int mid = (lo + hi) / 2;
      build(2 * node + 1, lo, mid);
      build(2 * node + 2, mid + 1, hi);
      for (auto x : tree[2 * node + 1]) tree[node].pb(x);
      for (auto x : tree[2 * node + 2]) tree[node].pb(x);
      sort(all(tree[node]));
      mint p = 1;
      for (auto x : tree[node]) {
        p = p * mint(x.s);
        prod[node].pb(p);
      }
    }
  }
  mint get(int node, int lo, int hi, int l, int r) {
    if (r < lo || hi < l) return 1;
    if (l <= lo && hi <= r) {
//      cout << "node " << node << endl;
      int i = 0, j = tree[node].size() - 1, ans = -1;
      while (i <= j) {
        int m = (i + j) / 2;
        if (tree[node][m].f < l) {
          ans = m;
          i = m + 1;
        } else {
          j = m - 1;
        }
      }
//      cout << "finbs\n";
//      cout << ans << endl;
//      cout << prod[node].size() << endl;
      mint res = ans == -1 ? 1 : prod[node][ans];
//      cout << "res " << res << endl;
      return res;
    }
    int mid = (lo + hi) / 2;
    return get(2 * node + 1, lo, mid, l, r) * get(2 * node + 2, mid + 1, hi, l, r);
  }
  mint query(int lo, int hi) {
    mint v = get(0, 0, n - 1, lo, hi);
//    cout << "v " << v << endl;
    return v;
  }
};

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  sieve();

  cin >> n;
  vi a(n);
  rep(i, 0, n) cin >> a[i];
  vi u(n, 1);
  rep(i, 0, n) {
    for (int pr : primes) {
      while (a[i] % pr == 0) {
        a[i] /= pr;
        u[i] *= pr;
      }
    }
  }

  small s(u);
  big b(a);

  int last = 0;
  int q;
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    int l = (last + x) % n;
    int r = (last + y) % n;
    if (l > r) swap(l, r);
//    cout << "~~ " << l << " " << r << endl;
    mint cur = s.query(l, r) * b.query(l, r);
    cout << cur  << endl;
    last = cur.x;
  }

  return 0;
}


#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define pii pair<int, int>
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vvl vector<vl>
#define vld vector<ld>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define vpll vector<pll>
#define rep(s, l, r) for (int s = l; s < r; s++)
#define per(s, r, l) for (int s = r - 1; s >= l; s--)
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef long double ld;
using namespace std;
template<class T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> void setmax(T& a, T b) { a = max(a, b); };
template<typename T> void setmin(T& a, T b) { a = min(a, b); };
template<typename T> bool in(T lo, T v, T hi) { return lo <= v && v <= hi; };

template<ll MOD>
struct ModInt {
  ll x = 0;
  ModInt() { x = 0; }
  ModInt(ll _x) {
    x = _x;
    if (x >= MOD || x <= -MOD) x %= MOD;
    if (x < 0) x += MOD;
  }
  friend ModInt operator+(ModInt a, ModInt b) {
    return ModInt(a.x + b.x);
  }
  friend ModInt operator-(ModInt a, ModInt b) {
    return ModInt(a.x - b.x);
  }
  friend ModInt operator*(ModInt a, ModInt b) {
    return ModInt(a.x * b.x);
  }
  friend ModInt operator/(ModInt a, ModInt b) {
    return a * inv(b);
  }
  friend ModInt power(ModInt a, ll b) {
    if (b == 0) return 1;
    ModInt c = power(a, b / 2);
    return c * c * ((b & 1) ? a : 1);
  }
  friend ModInt inv(ModInt a) {
    // this only works for nonzero elements
    return power(a, MOD - 2);
  }
  friend ostream& operator<<(ostream &os, const ModInt a) {
    os << a.x;
    return os;
  }
};

using mint = ModInt<1000000007>;

const int N = 1e5 + 10;
const int R = 318;
int n;
vi primes; // <= sqrt

void sieve() {
  vi pr(R, 1);
  for (int i = 2; i < R; i++) {
    if (pr[i]) {
      primes.pb(i);
      for (int j = 2 * i; j < R; j += i) pr[j] = false;
    }
  }
}

struct small {
  vector<map<int, int>> tree;
  vi a;
  small(vi _a) {
    a = _a;
    tree.resize(4 * n);
    build(0, 0, n - 1);
  }
  map<int, int> merge(map<int, int> a, map<int, int> b) {
    map<int, int> c;
    for (auto& [p, e] : a) c[p] = e;
    for (auto& [p, e] : b) setmax(c[p], e);
    return c;
  }
  void build(int node, int lo, int hi) {
    if (lo == hi) {
      for (int pr : primes) {
        int aa = a[lo];
        while (aa % pr == 0) {
          tree[node][pr]++; aa /= pr;
        }
      }
    } else {
      int mid = (lo + hi) / 2;
      build(2 * node + 1, lo, mid);
      build(2 * node + 2, mid + 1, hi);
      tree[node] = merge(tree[2 * node + 1], tree[2 * node + 2]);
    }
  }
  map<int, int> get(int node, int lo, int hi, int l, int r) {
    if (r < lo || hi < l) {
      return {};
    }
    if (l <= lo && hi <= r) {
      return tree[node];
    }
    int mid = (lo + hi) / 2;
    return merge(get(2 * node + 1, lo, mid, l, r), get(2 * node + 2, mid + 1, hi, l, r));
  }
  mint query(int lo, int hi) {
    map<int, int> m = get(0, 0, n - 1, lo, hi);
    mint res = 1;
    for (auto &[p, e] : m) {
      res = res * power(mint(p), e);
    }
    return res;
  }
};

struct big {
  vvpii tree;
  vector<vector<mint>> prod;
  vi a;
  vi prev;
  big(vi _a) {
    a = _a;
    prev.assign(n, -1);
    map<int, int> p;
    rep(i, 0, n) {
      prev[i] = p.count(a[i]) ? p[a[i]] : -1;
      p[a[i]] = i;
    }
    tree.resize(4 * n);
    prod.resize(4 * n);
    build(0, 0, n - 1);
  }
  void build(int node, int lo, int hi) {
    if (lo == hi) {
      tree[node] = {{prev[lo], a[lo]}};
    } else {
      for (auto x : tree[2 * node + 1]) tree[node].pb(x);
      for (auto x : tree[2 * node + 2]) tree[node].pb(x);
      sort(all(tree[node]));
      mint p = 1;
      for (auto x : tree[node]) {
        p = p * mint(x.s);
        prod[node].pb(p);
      }
    }
  }
  mint get(int node, int lo, int hi, int l, int r) {
    if (r < lo || hi < l) return 1;
    if (l <= lo && hi <= r) {
      int i = 0, j = int(tree[node].size()) - 1, ans = -1;
      while (i <= j) {
        int m = (i + j) / 2;
        if (tree[node][m].f < l) {
          ans = m;
          i = m + 1;
        } else {
          j = m - 1;
        }
      }
      return ans == -1 ? 1 : prod[node][ans];
    }
    int mid = (lo + hi) / 2;
    return get(2 * node + 1, lo, mid, l, r) * get(2 * node + 2, mid + 1, hi, l, r);
  }
  mint query(int lo, int hi) {
    return get(0, 0, n - 1, lo, hi);
  }
};

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  sieve();

  cin >> n;
  vi a(n);
  rep(i, 0, n) cin >> a[i];
  vi u(n, 1);
  rep(i, 0, n) {
    for (int pr : primes) {
      while (a[i] % pr == 0) {
        a[i] /= pr;
        u[i] *= pr;
      }
    }
  }

  small s(u);
  big b(a);

  int last = 0;
  int q;
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    int l = (last + x) % n;
    int r = (last + y) % n;
    if (l > r) swap(l, r);
//    cout << "~~ " << l << " " << r << endl;
    mint cur = s.query(l, r) * b.query(l, r);
    cout << cur  << endl;
    last = cur.x;
  }

  return 0;
}


#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define pii pair<int, int>
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vvl vector<vl>
#define vld vector<ld>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define vpll vector<pll>
#define rep(s, l, r) for (int s = l; s < r; s++)
#define per(s, r, l) for (int s = r - 1; s >= l; s--)
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef long double ld;
using namespace std;
template<class T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> void setmax(T& a, T b) { a = max(a, b); };
template<typename T> void setmin(T& a, T b) { a = min(a, b); };
template<typename T> bool in(T lo, T v, T hi) { return lo <= v && v <= hi; };

template<ll MOD>
struct ModInt {
  ll x = 0;
  ModInt() { x = 0; }
  ModInt(ll _x) {
    x = _x;
    if (x >= MOD || x <= -MOD) x %= MOD;
    if (x < 0) x += MOD;
  }
  friend ModInt operator+(ModInt a, ModInt b) {
    return ModInt(a.x + b.x);
  }
  friend ModInt operator-(ModInt a, ModInt b) {
    return ModInt(a.x - b.x);
  }
  friend ModInt operator*(ModInt a, ModInt b) {
    return ModInt(a.x * b.x);
  }
  friend ModInt operator/(ModInt a, ModInt b) {
    return a * inv(b);
  }
  friend ModInt power(ModInt a, ll b) {
    if (b == 0) return 1;
    ModInt c = power(a, b / 2);
    return c * c * ((b & 1) ? a : 1);
  }
  friend ModInt inv(ModInt a) {
    // this only works for nonzero elements
    return power(a, MOD - 2);
  }
  friend ostream& operator<<(ostream &os, const ModInt a) {
    os << a.x;
    return os;
  }
};

using mint = ModInt<1000000007>;

const int N = 1e5 + 10;
const int R = 318;
int n;
vi primes; // <= sqrt

void sieve() {
  vi pr(R, 1);
  for (int i = 2; i < R; i++) {
    if (pr[i]) {
      primes.pb(i);
      for (int j = 2 * i; j < R; j += i) pr[j] = 0;
    }
  }
}

struct small {
  vector<map<int, int>> tree;
  vi a;
  small(vi _a) {
    a = _a;
    tree.resize(4 * n);
    build(0, 0, n - 1);
  }
  map<int, int> merge(map<int, int> a, map<int, int> b) {
    map<int, int> c;
    for (auto& [p, e] : a) c[p] = e;
    for (auto& [p, e] : b) setmax(c[p], e);
    return c;
  }
  void build(int node, int lo, int hi) {
    if (lo == hi) {
      for (int pr : primes) {
        int aa = a[lo];
        while (aa % pr == 0) {
          tree[node][pr]++; aa /= pr;
        }
      }
    } else {
      int mid = (lo + hi) / 2;
      build(2 * node + 1, lo, mid);
      build(2 * node + 2, mid + 1, hi);
      tree[node] = merge(tree[2 * node + 1], tree[2 * node + 2]);
    }
  }
  map<int, int> get(int node, int lo, int hi, int l, int r) {
    if (r < lo || hi < l) {
      return {};
    }
    if (l <= lo && hi <= r) {
      return tree[node];
    }
    int mid = (lo + hi) / 2;
    return merge(get(2 * node + 1, lo, mid, l, r), get(2 * node + 2, mid + 1, hi, l, r));
  }
  mint query(int lo, int hi) {
    map<int, int> m = get(0, 0, n - 1, lo, hi);
    mint res = 1;
    for (auto &[p, e] : m) {
      res = res * power(mint(p), e);
    }
    return res;
  }
};

struct big {
  vvpii tree;
  vector<vector<mint>> prod;
  vi a;
  vi prev;
  big(vi _a) {
    a = _a;
    prev.assign(n, -1);
    map<int, int> p;
    rep(i, 0, n) {
      prev[i] = p.count(a[i]) ? p[a[i]] : -1;
      p[a[i]] = i;
    }
    tree.resize(4 * n);
    prod.resize(4 * n);
    build(0, 0, n - 1);
  }
  void build(int node, int lo, int hi) {
    if (lo == hi) {
      tree[node] = {{prev[lo], a[lo]}};
      prod[node] = { a[lo] };
    } else {
      int mid = (lo + hi) / 2;
      build(2 * node + 1, lo, mid);
      build(2 * node + 2, mid + 1, hi);
      for (auto x : tree[2 * node + 1]) tree[node].pb(x);
      for (auto x : tree[2 * node + 2]) tree[node].pb(x);
      sort(all(tree[node]));
      mint p = 1;
      for (auto x : tree[node]) {
        p = p * mint(x.s);
        prod[node].pb(p);
      }
    }
  }
  mint get(int node, int lo, int hi, int l, int r) {
    if (r < lo || hi < l) return 1;
    if (l <= lo && hi <= r) {
      int cnt = lower_bound(all(tree[node]), make_pair(l + 1, 0)) - tree[node].begin();
      mint res = cnt == 0 ? 1 : prod[node][cnt - 1];
      return res;
    }
    int mid = (lo + hi) / 2;
    return get(2 * node + 1, lo, mid, l, r) * get(2 * node + 2, mid + 1, hi, l, r);
  }
  mint query(int lo, int hi) {
    return get(0, 0, n - 1, lo, hi);
  }
};

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  sieve();

  cin >> n;
  vi a(n);
  rep(i, 0, n) cin >> a[i];
  vi u(n, 1);
  rep(i, 0, n) {
    for (int pr : primes) {
      while (a[i] % pr == 0) {
        a[i] /= pr;
        u[i] *= pr;
      }
    }
  }

  small s(u);
  big b(a);

  int last = 0;
  int q;
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    int l = (last + x) % n;
    int r = (last + y) % n;
    if (l > r) swap(l, r);
//    cout << "~~ " << l << " " << r << endl;
//    cout << s.query(l, r) << endl;
//    cout << b.query(l, r) << endl;
    mint cur = s.query(l, r) * b.query(l, r);
    cout << cur  << endl;
    last = cur.x;
  }

  return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/STACK:16777216")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>

using namespace std;
using namespace __gnu_pbds;

#define LL long long
//#define int long long
#define ull unsigned long long
#define fi first
#define se second
#define pll pair<LL, LL>
#define pii pair<LL, LL>
#define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define SZ(x) ((int)(x.size()))
#define LC (id<<1)
#define RC (id<<1|1)

constexpr int N = 2e5+9;
constexpr int M = 1e9+7;
#ifdef int
constexpr int INF = 0x3f3f3f3f3f3f3f3f;
constexpr int INF2 = 0xcfcfcfcfcfcfcfcf;
#else
constexpr int INF = 0x3f3f3f3f;
constexpr int INF2 = 0xcfcfcfcf;
#endif

inline int qpow(int a, int b) {
    int c = 1;
    while (b) {
        if (b & 1) c = 1ll * c * a % M;
        a = 1ll * a * a % M;
        b >>= 1;
    }
    return c;
}
bool prime[N];
vector<int> primes;
vector<int> inv[N];
vector<pii> st[N];
void init() {
    memset(prime, 1, sizeof(prime));
    for (int i = 2; i < N; i++) {
        if (prime[i]) {
            primes.emplace_back(i);
            int lg = 1;
            LL k = i;
            while (k * i < N) {
                lg++;
                k *= i;
            }
            inv[i].resize(lg+1);
            inv[i][0] = 1;
            inv[i][1] = qpow(i, M-2);
            for (int j = 2; j <= lg; j++)
                inv[i][j] = 1ll * inv[i][j-1] * inv[i][1] % M;
            for (LL j = 1LL * i * i; j < N; j += i)
                prime[j] = false;
        }
    }
}

int n, q, tot;
struct Node {
    int lc, rc, val;
} node[static_cast<int>(250e6 / sizeof(Node))];
constexpr int MAXN = static_cast<int>(250e6 / sizeof(Node));
int rt[N], root;
inline int build(int id) {
    node[++tot].val = 1;
    node[tot].lc = node[id].lc;
    node[tot].rc = node[id].rc;
    return tot;
}
inline void maintain(int id) {
    if (!node[id].lc) node[id].lc = build(0);
    if (!node[id].rc) node[id].rc = build(0);
}
int update(int id, int l, int r, int pos, int val) {
    //cout << id << " " << l << " " << r << " " << pos << " " << val << endl;
    int res = build(id);
    if (l == r) {
        node[res].val = 1ll * node[id].val * val % M;
        return res;
    }
    maintain(res);
    int m = (l+r)>>1;
    if (pos <= m) node[res].lc = update(node[res].lc, l, m, pos, val);
    else node[res].rc = update(node[res].rc, m+1, r, pos, val);
    node[res].val = 1ll * node[node[res].lc].val * node[node[res].rc].val % M;
    return res;
}
int query(int id, int l, int r, int s, int e) {
    //cout << id << " " << l << " " << r << " " << s << " " << e << endl;
    if (l == s && r == e) return node[id].val;
    maintain(id);
    int m = (l+r)>>1;
    if (e <= m) return query(node[id].lc, l, m, s, e);
    else if (s > m) return query(node[id].rc, m+1, r, s, e);
    return 1ll * query(node[id].lc, l, m, s, m) * query(node[id].rc, m+1, r, m+1, e) % M;
}
void produce(int x, int p, int cnt) {
    //cout << "produce " << x << " " << p << " " << cnt << endl;
    int left = cnt;
    while (!st[p].empty() && left) {
        auto pr = st[p].back();
        st[p].pop_back();
        if (left < pr.se) {
            root = update(root, 1, n, pr.fi, inv[p][left]);
            st[p].emplace_back(pr.fi, pr.se - left), left = 0;
        } else {
            root = update(root, 1, n, pr.fi, inv[p][pr.se]);
            left -= pr.se;
        }
    }
    st[p].emplace_back(x, cnt);
    int val = 1;
    for (int j = 0; j < cnt; j++)
        val = val * p;
    root = update(root, 1, n, x, val);
}
int append(int i, int x) {
    for (const int& p: primes) {
        if (p * p > x) break;
        if (x % p) continue;
        int cnt = 0;
        while (x % p == 0) cnt++, x /= p;
        produce(i, p, cnt);
    }
    if (x != 1) produce(i, x, 1);
    return root;
}

signed main() {
    fastio;
    init();
    cin >> n;
    root = build(0);
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        rt[i] = append(i, x);
    }
    cin >> q;
    int last = 0;
    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 << ":";
        last = query(rt[r], 1, n, l, r);
        cout << last << "\n";
        //break;
    }
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/STACK:16777216")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>

using namespace std;
using namespace __gnu_pbds;

#define LL long long
//#define int long long
#define ull unsigned long long
#define fi first
#define se second
#define pll pair<LL, LL>
#define pii pair<LL, LL>
#define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define SZ(x) ((int)(x.size()))
#define LC (id<<1)
#define RC (id<<1|1)

constexpr int N = 2e5+9;
constexpr int M = 1e9+7;
#ifdef int
constexpr int INF = 0x3f3f3f3f3f3f3f3f;
constexpr int INF2 = 0xcfcfcfcfcfcfcfcf;
#else
constexpr int INF = 0x3f3f3f3f;
constexpr int INF2 = 0xcfcfcfcf;
#endif

inline int qpow(int a, int b) {
    int c = 1;
    while (b) {
        if (b & 1) c = 1ll * c * a % M;
        a = 1ll * a * a % M;
        b >>= 1;
    }
    return c;
}
bool prime[N];
vector<int> primes;
vector<int> inv[N];
vector<pii> st[N];
void init() {
    memset(prime, 1, sizeof(prime));
    for (int i = 2; i < N; i++) {
        if (prime[i]) {
            primes.emplace_back(i);
            if (1ll * i * i >= N) break;
            for (int j = i * i; j < N; j += i)
                prime[j] = false;
            int lg = 1;
            LL k = i;
            while (k * i < N) {
                lg++;
                k *= i;
            }
            inv[i].resize(lg+1);
            inv[i][0] = 1;
            inv[i][1] = qpow(i, M-2);
            for (int j = 2; j <= lg; j++)
                inv[i][j] = 1ll * inv[i][j-1] * inv[i][1] % M;
        }
    }
}

int n, q, tot;
struct Node {
    int lc, rc, val;
} node[static_cast<int>(250e6 / sizeof(Node))];
int rt[N], root;
inline int build(int id) {
    node[++tot].val = 1;
    node[tot].lc = node[id].lc;
    node[tot].rc = node[id].rc;
    return tot;
}
inline void maintain(int id) {
    if (!node[id].lc) node[id].lc = build(0);
    if (!node[id].rc) node[id].rc = build(0);
}
int update(int id, int l, int r, int pos, int val) {
    //cout << id << " " << l << " " << r << " " << pos << " " << val << endl;
    int res = build(id);
    if (l == r) {
        node[res].val = 1ll * node[id].val * val % M;
        return res;
    }
    maintain(res);
    int m = (l+r)>>1;
    if (pos <= m) node[res].lc = update(node[res].lc, l, m, pos, val);
    else node[res].rc = update(node[res].rc, m+1, r, pos, val);
    node[res].val = 1ll * node[node[res].lc].val * node[node[res].rc].val % M;
    return res;
}
int query(int id, int l, int r, int s, int e) {
    //cout << id << " " << l << " " << r << " " << s << " " << e << endl;
    if (l == s && r == e) return node[id].val;
    maintain(id);
    int m = (l+r)>>1;
    if (e <= m) return query(node[id].lc, l, m, s, e);
    else if (s > m) return query(node[id].rc, m+1, r, s, e);
    return 1ll * query(node[id].lc, l, m, s, m) * query(node[id].rc, m+1, r, m+1, e) % M;
}
void produce(int x, int p, int cnt) {
    int left = cnt;
    while (!st[p].empty() && left) {
        auto pr = st[p].back();
        st[p].pop_back();
        if (left < pr.se) {
            root = update(root, 1, n, pr.fi, inv[p][left]);
            st[p].emplace_back(pr.fi, pr.se - left), left = 0;
        } else {
            root = update(root, 1, n, pr.fi, inv[p][pr.se]);
            left -= pr.se;
        }
    }
    st[p].emplace_back(x, cnt);
    int val = 1;
    for (int j = 0; j < cnt; j++)
        val = 1ll * val * p;
    root = update(root, 1, n, x, val);
}
int append(int i, int x) {
    for (const int& p: primes) {
        if (p * p > x) break;
        if (x % p) continue;
        int cnt = 0;
        while (x % p == 0) cnt++, x /= p;
        produce(i, p, cnt);
    }
    if (x != 1) produce(i, x, 1);
    return root;
}

signed main() {
    fastio;
    init();
    cin >> n;
    root = build(0);
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        rt[i] = append(i, x);
    }
    cin >> q;
    int last = 0;
    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 << ":";
        last = query(rt[r], 1, n, l, r);
        cout << last << "\n";
        //break;
    }
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/STACK:16777216")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>

using namespace std;
using namespace __gnu_pbds;

#define LL long long
#define int long long
#define ull unsigned long long
#define fi first
#define se second
#define pll pair<LL, LL>
#define pii pair<LL, LL>
#define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define SZ(x) ((int)(x.size()))
#define LC (id<<1)
#define RC (id<<1|1)

constexpr int N = 2e5+9;
constexpr int M = 1e9+7;
#ifdef int
constexpr int INF = 0x3f3f3f3f3f3f3f3f;
constexpr int INF2 = 0xcfcfcfcfcfcfcfcf;
#else
constexpr int INF = 0x3f3f3f3f;
constexpr int INF2 = 0xcfcfcfcf;
#endif

inline int qpow(int a, int b) {
    int c = 1;
    while (b) {
        if (b & 1) c = 1ll * c * a % M;
        a = 1ll * a * a % M;
        b >>= 1;
    }
    return c;
}
bool prime[N];
vector<int> primes;
vector<int> inv[N];
vector<pii> st[N];
void init() {
    memset(prime, 1, sizeof(prime));
    for (int i = 2; i < N; i++) {
        if (prime[i]) {
            primes.emplace_back(i);
            int lg = 1;
            LL k = i;
            while (k * i < N) {
                lg++;
                k *= i;
            }
            inv[i].resize(lg+1);
            inv[i][0] = 1;
            inv[i][1] = qpow(i, M-2);
            for (int j = 2; j <= lg; j++)
                inv[i][j] = 1ll * inv[i][j-1] * inv[i][1] % M;
            for (LL j = 1LL * i * i; j < N; j += i)
                prime[j] = false;
        }
    }
}

int n, q, tot;
struct Node {
    int lc, rc, val;
} node[static_cast<int>(480e6 / sizeof(Node))];
constexpr int MAXN = static_cast<int>(480e6 / sizeof(Node));
int rt[N], root;
inline int build(int id) {
    node[++tot].val = 1;
    node[tot].lc = node[id].lc;
    node[tot].rc = node[id].rc;
    return tot;
}
inline void maintain(int id) {
    if (!node[id].lc) node[id].lc = build(0);
    if (!node[id].rc) node[id].rc = build(0);
}
int update(int id, int l, int r, int pos, int val) {
    //cout << id << " " << l << " " << r << " " << pos << " " << val << endl;
    int res = build(id);
    if (l == r) {
        node[res].val = 1ll * node[id].val * val % M;
        return res;
    }
    maintain(res);
    int m = (l+r)>>1;
    if (pos <= m) node[res].lc = update(node[res].lc, l, m, pos, val);
    else node[res].rc = update(node[res].rc, m+1, r, pos, val);
    node[res].val = 1ll * node[node[res].lc].val * node[node[res].rc].val % M;
    return res;
}
int query(int id, int l, int r, int s, int e) {
    //cout << id << " " << l << " " << r << " " << s << " " << e << endl;
    if (l == s && r == e) return node[id].val;
    maintain(id);
    int m = (l+r)>>1;
    if (e <= m) return query(node[id].lc, l, m, s, e);
    else if (s > m) return query(node[id].rc, m+1, r, s, e);
    return 1ll * query(node[id].lc, l, m, s, m) * query(node[id].rc, m+1, r, m+1, e) % M;
}
void produce(int x, int p, int cnt) {
    //cout << "produce " << x << " " << p << " " << cnt << endl;
    int left = cnt;
    while (!st[p].empty() && left) {
        auto pr = st[p].back();
        st[p].pop_back();
        if (left < pr.se) {
            root = update(root, 1, n, pr.fi, inv[p][left]);
            st[p].emplace_back(pr.fi, pr.se - left), left = 0;
        } else {
            root = update(root, 1, n, pr.fi, inv[p][pr.se]);
            left -= pr.se;
        }
    }
    st[p].emplace_back(x, cnt);
    int val = 1;
    for (int j = 0; j < cnt; j++)
        val = val * p;
    root = update(root, 1, n, x, val);
}
int append(int i, int x) {
    for (const int& p: primes) {
        if (p * p > x) break;
        if (x % p) continue;
        int cnt = 0;
        while (x % p == 0) cnt++, x /= p;
        produce(i, p, cnt);
    }
    if (x != 1) produce(i, x, 1);
    return root;
}

signed main() {
    fastio;
    init();
    cin >> n;
    root = build(0);
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        rt[i] = append(i, x);
    }
    cin >> q;
    int last = 0;
    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 << ":";
        last = query(rt[r], 1, n, l, r);
        cout << last << "\n";
        //break;
    }
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/STACK:16777216")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>

using namespace std;
using namespace __gnu_pbds;

#define LL long long
//#define int long long
#define ull unsigned long long
#define fi first
#define se second
#define pll pair<LL, LL>
#define pii pair<LL, LL>
#define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define SZ(x) ((int)(x.size()))
#define LC (id<<1)
#define RC (id<<1|1)

constexpr int N = 2e5+9;
constexpr int M = 1e9+7;
#ifdef int
constexpr int INF = 0x3f3f3f3f3f3f3f3f;
constexpr int INF2 = 0xcfcfcfcfcfcfcfcf;
#else
constexpr int INF = 0x3f3f3f3f;
constexpr int INF2 = 0xcfcfcfcf;
#endif

inline int qpow(int a, int b) {
    int c = 1;
    while (b) {
        if (b & 1) c = 1ll * c * a % M;
        a = 1ll * a * a % M;
        b >>= 1;
    }
    return c;
}
bool prime[N];
vector<int> primes;
vector<int> inv[N];
vector<int> st[N];
void init() {
    memset(prime, 1, sizeof(prime));
    for (int i = 2; i < N; i++) {
        if (prime[i]) {
            primes.emplace_back(i);
            if (1ll * i * i >= N) break;
            for (int j = i * i; j < N; j += i)
                prime[j] = false;
            int lg = 1;
            LL k = i;
            while (k * i < N) {
                lg++;
                k *= i;
            }
            st[i].resize(lg+1);
            inv[i].resize(lg+1);
            for (int& j: st[i]) j = 0;
            inv[i][0] = 1;
            inv[i][1] = qpow(i, M-2);
            for (int j = 2; j <= lg; j++)
                inv[i][j] = 1ll * inv[i][j-1] * inv[i][1] % M;
        }
    }
}

int n, q, tot;
struct Node {
    int lc, rc, val;
} node[static_cast<int>(250e6 / sizeof(Node))];
int rt[N], root;
inline int build(int id) {
    node[++tot].val = 1;
    node[tot].lc = node[id].lc;
    node[tot].rc = node[id].rc;
    return tot;
}
inline void maintain(int id) {
    if (!node[id].lc) node[id].lc = build(0);
    if (!node[id].rc) node[id].rc = build(0);
}
int update(int id, int l, int r, int pos, int val) {
    //cout << id << " " << l << " " << r << " " << pos << " " << val << endl;
    int res = build(id);
    if (l == r) {
        node[res].val = 1ll * node[id].val * val % M;
        return res;
    }
    maintain(res);
    int m = (l+r)>>1;
    if (pos <= m) node[res].lc = update(node[res].lc, l, m, pos, val);
    else node[res].rc = update(node[res].rc, m+1, r, pos, val);
    node[res].val = 1ll * node[node[res].lc].val * node[node[res].rc].val % M;
    return res;
}
int query(int id, int l, int r, int s, int e) {
    //cout << id << " " << l << " " << r << " " << s << " " << e << endl;
    if (l == s && r == e) return node[id].val;
    maintain(id);
    int m = (l+r)>>1;
    if (e <= m) return query(node[id].lc, l, m, s, e);
    else if (s > m) return query(node[id].rc, m+1, r, s, e);
    return 1ll * query(node[id].lc, l, m, s, m) * query(node[id].rc, m+1, r, m+1, e) % M;
}
void produce(int x, int p, int cnt) {
    for (int i = 1; i < SZ(st[p]); i++) {
        auto& ps = st[p][i];
        if (!ps) {
            if (i == cnt) ps = i;
            continue;
        }
        if (i <= cnt) root = update(root, 1, n, ps, inv[p][i]); //cout <<x<<":"<< ps << " /" << p << " " << i << "\n";
        else root = update(root, 1, n, ps, inv[p][cnt]); //cout <<x<<":"<< ps << " /" << p << " " << cnt << "\n";
        if (i > cnt) st[p][i-cnt] = ps;
        ps = 0;
    }
    st[p][cnt] = x;
    int val = 1;
    for (int j = 0; j < cnt; j++)
        val = 1ll * val * p;
    root = update(root, 1, n, x, val);
}
int append(int i, int x) {
    //for (int j = 1; j <= 10; j++)
    //    if (st[2][j]) cout << st[2][j] << ":" << j << " ";cout << endl;
    for (const int& p: primes) {
        if (p * p > x) break;
        if (x % p) continue;
        int cnt = 0;
        while (x % p == 0) cnt++, x /= p;
        produce(i, p, cnt);
    }
    if (x != 1) produce(i, x, 1);
    return root;
}

signed main() {
    fastio;
    init();
    cin >> n;
    root = build(0);
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        rt[i] = append(i, x);
    }
    cin >> q;
    int last = 0;
    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 << ":";
        last = query(rt[r], 1, n, l, r);
        cout << last << "\n";
        //break;
    }
    return 0;
}