#include <bits/stdc++.h>
using namespace std;
char _;
const int maxN = 200 * 1000 + 5;
const int mod = 1000 * 1000 * 1000 + 7;
const int base = 701;
const int SQ = 600;
const int maxL = 302;
int seg[4 * maxN];
void add(int p, int val, int s, int e, int ind) {
  seg[ind] = (1LL) * seg[ind] * val % mod;
  if (e - s == 1) return;
  int mid = (s + e) >> 1;
  if (p < mid)
    add(p, val, s, mid, 2 * ind);
  else
    add(p, val, mid, e, 2 * ind + 1);
}
int get(int l, int r, int s, int e, int ind) {
  if (l >= e || r <= s) return 1;
  if (l <= s && e <= r) return seg[ind];
  int mid = (s + e) >> 1;
  return (1LL) * get(l, r, s, mid, 2 * ind) * get(l, r, mid, e, 2 * ind + 1) %
         mod;
}
int power(int n, int k) {
  if (k == 0) return 1;
  int ans = power(n, k / 2);
  ans = (1LL) * ans * ans % mod;
  if (k & 1) ans = (1LL) * ans * n % mod;
  return ans;
}
int a[maxN];
int las[5 * maxN];
int cur[5 * maxN];
vector<pair<int, int> > que[maxN];
int ans[maxN];
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  for (int i = 0; i < 4 * maxN; i++) seg[i] = 1;
  for (int i = 2; i < 5 * maxN; i++)
    if (las[i] == 0)
      for (int j = i; j < 5 * maxN; j += i) las[j] = i;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    l--;
    r--;
    que[r].push_back({l, i});
  }
  memset(cur, -1, sizeof cur);
  for (int i = 0; i < n; i++) {
    int tmp = a[i];
    while (tmp > 1) {
      int xx = las[tmp], cnt = 0;
      while (tmp % xx == 0) tmp /= xx, cnt++;
      if (cur[xx] > -1) {
        int tt = (1LL) * xx * power(xx - 1, mod - 2) % mod;
        add(cur[xx], tt, 0, n, 1);
      }
      int tt = (1LL) * (xx - 1) * power(xx, cnt - 1) % mod;
      add(i, tt, 0, n, 1);
      cur[xx] = i;
    }
    for (int j = 0; j < (int)que[i].size(); j++)
      ans[que[i][j].second] = get(que[i][j].first, i + 1, 0, n, 1);
  }
  for (int i = 0; i < q; i++) cout << ans[i] << endl;
  return 0;
}

### Prompt

Develop a solution in Cpp to the problem described below:

Today on a math lesson the teacher told Vovochka that the Euler function of a positive integer φ(n) is an arithmetic function that counts the positive integers less than or equal to n that are relatively prime to n. The number 1 is coprime to all the positive integers and φ(1) = 1.

Now the teacher gave Vovochka an array of n positive integers a1, a2, ..., an and a task to process q queries li ri — to calculate and print <image> modulo 109 + 7. As it is too hard for a second grade school student, you've decided to help Vovochka.

Input

The first line of the input contains number n (1 ≤ n ≤ 200 000) — the length of the array given to Vovochka. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106).

The third line contains integer q (1 ≤ q ≤ 200 000) — the number of queries. Next q lines contain the queries, one per line. Each query is defined by the boundaries of the segment li and ri (1 ≤ li ≤ ri ≤ n).

Output

Print q numbers — the value of the Euler function for each query, calculated modulo 109 + 7.

Examples

Input

10
1 2 3 4 5 6 7 8 9 10
7
1 1
3 8
5 6
4 8
8 10
7 9
7 10


Output

1
4608
8
1536
192
144
1152


Input

7
24 63 13 52 6 10 1
6
3 5
4 7
1 7
2 4
3 6
2 6


Output

1248
768
12939264
11232
9984
539136

Note

In the second sample the values are calculated like that:

  * φ(13·52·6) = φ(4056) = 1248
  * φ(52·6·10·1) = φ(3120) = 768
  * φ(24·63·13·52·6·10·1) = φ(61326720) = 12939264
  * φ(63·13·52) = φ(42588) = 11232
  * φ(13·52·6·10) = φ(40560) = 9984
  * φ(63·13·52·6·10) = φ(2555280) = 539136

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
char _;
const int maxN = 200 * 1000 + 5;
const int mod = 1000 * 1000 * 1000 + 7;
const int base = 701;
const int SQ = 600;
const int maxL = 302;
int seg[4 * maxN];
void add(int p, int val, int s, int e, int ind) {
  seg[ind] = (1LL) * seg[ind] * val % mod;
  if (e - s == 1) return;
  int mid = (s + e) >> 1;
  if (p < mid)
    add(p, val, s, mid, 2 * ind);
  else
    add(p, val, mid, e, 2 * ind + 1);
}
int get(int l, int r, int s, int e, int ind) {
  if (l >= e || r <= s) return 1;
  if (l <= s && e <= r) return seg[ind];
  int mid = (s + e) >> 1;
  return (1LL) * get(l, r, s, mid, 2 * ind) * get(l, r, mid, e, 2 * ind + 1) %
         mod;
}
int power(int n, int k) {
  if (k == 0) return 1;
  int ans = power(n, k / 2);
  ans = (1LL) * ans * ans % mod;
  if (k & 1) ans = (1LL) * ans * n % mod;
  return ans;
}
int a[maxN];
int las[5 * maxN];
int cur[5 * maxN];
vector<pair<int, int> > que[maxN];
int ans[maxN];
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  for (int i = 0; i < 4 * maxN; i++) seg[i] = 1;
  for (int i = 2; i < 5 * maxN; i++)
    if (las[i] == 0)
      for (int j = i; j < 5 * maxN; j += i) las[j] = i;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    l--;
    r--;
    que[r].push_back({l, i});
  }
  memset(cur, -1, sizeof cur);
  for (int i = 0; i < n; i++) {
    int tmp = a[i];
    while (tmp > 1) {
      int xx = las[tmp], cnt = 0;
      while (tmp % xx == 0) tmp /= xx, cnt++;
      if (cur[xx] > -1) {
        int tt = (1LL) * xx * power(xx - 1, mod - 2) % mod;
        add(cur[xx], tt, 0, n, 1);
      }
      int tt = (1LL) * (xx - 1) * power(xx, cnt - 1) % mod;
      add(i, tt, 0, n, 1);
      cur[xx] = i;
    }
    for (int j = 0; j < (int)que[i].size(); j++)
      ans[que[i][j].second] = get(que[i][j].first, i + 1, 0, n, 1);
  }
  for (int i = 0; i < q; i++) cout << ans[i] << endl;
  return 0;
}

```