#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 85 - 69;
const int maxval = 1e6 + 85 - 69;
const long long int Mod = 1e9 + 7;
vector<int> facts[maxval];
bool rev_filled[maxval];
long long int rev[maxval];
long long int seg1[maxn * 4], seg2[maxn * 7 * 4];
long long int a[maxn];
int n, q;
long long int ans[maxn], sttime[maxn], fitime[maxn];
long long int adss[maxval], last[maxn * 7];
vector<long long int> vec;
pair<pair<long long int, long long int>, long long int> quer[maxn];
void build1(int l = 0, int r = n, int id = 1) {
  if (r - l == 1) {
    seg1[id] = a[l];
    return;
  }
  int mid = (l + r) >> 1;
  build1(l, mid, id * 2 + 0);
  build1(mid, r, id * 2 + 1);
  seg1[id] = (seg1[id * 2 + 0] * seg1[id * 2 + 1]) % Mod;
  return;
}
long long int get1(int st, int en, int l = 0, int r = n, int id = 1) {
  if (st >= r or en <= l) return 1;
  if (st <= l and r <= en) return seg1[id];
  int mid = (l + r) >> 1;
  return (get1(st, en, l, mid, id * 2 + 0) * get1(st, en, mid, r, id * 2 + 1)) %
         Mod;
}
void modify2(int idx, long long int val, int l = 0, int r = ((int)(vec).size()),
             int id = 1) {
  if (idx < l or idx >= r) return;
  if (r - l == 1) {
    seg2[id] = val;
    return;
  }
  int mid = (l + r) >> 1;
  modify2(idx, val, l, mid, id * 2 + 0);
  modify2(idx, val, mid, r, id * 2 + 1);
  seg2[id] = (seg2[id * 2 + 0] * seg2[id * 2 + 1]) % Mod;
  return;
}
long long int get2(int st, int en, int l = 0, int r = ((int)(vec).size()),
                   int id = 1) {
  if (st >= r or en <= l) return 1;
  if (st <= l and r <= en) return seg2[id];
  int mid = (l + r) >> 1;
  return (get2(st, en, l, mid, id * 2 + 0) * get2(st, en, mid, r, id * 2 + 1)) %
         Mod;
}
bool cmp(pair<pair<long long int, long long int>, long long int> x,
         pair<pair<long long int, long long int>, long long int> y) {
  return x.first.second < y.first.second;
}
void find_primes(void) {
  for (int i = 2; i < maxval; i++)
    if (facts[i].size() == 0)
      for (int j = i; j < maxval; j += i) facts[j].push_back(i);
  return;
}
long long int Pow(long long int x, long long int y) {
  long long int ret = 1, an = x;
  for (int i = 0; y; i++, an = (an * an) % Mod)
    if ((y >> i) & 1LL) ret = (ret * an) % Mod, y ^= (1LL << i);
  return ret;
}
long long int Div(long long int x, long long int y) {
  return (x * Pow(y, Mod - 2)) % Mod;
}
long long int Rev(long long int x) {
  if (rev_filled[x]) return rev[x];
  rev_filled[x] = true;
  return rev[x] = Div(1, x);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  memset(adss, -1, sizeof adss);
  find_primes();
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sttime[i] = ((int)(vec).size());
    for (auto f : facts[a[i]]) {
      last[((int)(vec).size())] = adss[f];
      adss[f] = ((int)(vec).size());
      vec.push_back(f);
    }
    fitime[i] = ((int)(vec).size());
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> quer[i].first.first >> quer[i].first.second;
    quer[i].first.first--;
    quer[i].second = i;
  }
  sort(quer, quer + q, cmp);
  build1();
  int p = 0;
  for (int i = 0; i < q; i++) {
    while (p < quer[i].first.second) {
      for (int j = sttime[p]; j < fitime[p]; j++) {
        modify2(last[j], 1);
        modify2(j, ((vec[j] - 1) * Rev(vec[j])) % Mod);
      }
      p++;
    }
    ans[quer[i].second] =
        (get1(quer[i].first.first, quer[i].first.second) *
         get2(sttime[quer[i].first.first], fitime[quer[i].first.second - 1])) %
        Mod;
  }
  for (int i = 0; i < q; i++) cout << ans[i] << '\n';
  return 0;
}

### Prompt

Your challenge is to write a Cpp solution to the following problem:

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;
const int maxn = 2e5 + 85 - 69;
const int maxval = 1e6 + 85 - 69;
const long long int Mod = 1e9 + 7;
vector<int> facts[maxval];
bool rev_filled[maxval];
long long int rev[maxval];
long long int seg1[maxn * 4], seg2[maxn * 7 * 4];
long long int a[maxn];
int n, q;
long long int ans[maxn], sttime[maxn], fitime[maxn];
long long int adss[maxval], last[maxn * 7];
vector<long long int> vec;
pair<pair<long long int, long long int>, long long int> quer[maxn];
void build1(int l = 0, int r = n, int id = 1) {
  if (r - l == 1) {
    seg1[id] = a[l];
    return;
  }
  int mid = (l + r) >> 1;
  build1(l, mid, id * 2 + 0);
  build1(mid, r, id * 2 + 1);
  seg1[id] = (seg1[id * 2 + 0] * seg1[id * 2 + 1]) % Mod;
  return;
}
long long int get1(int st, int en, int l = 0, int r = n, int id = 1) {
  if (st >= r or en <= l) return 1;
  if (st <= l and r <= en) return seg1[id];
  int mid = (l + r) >> 1;
  return (get1(st, en, l, mid, id * 2 + 0) * get1(st, en, mid, r, id * 2 + 1)) %
         Mod;
}
void modify2(int idx, long long int val, int l = 0, int r = ((int)(vec).size()),
             int id = 1) {
  if (idx < l or idx >= r) return;
  if (r - l == 1) {
    seg2[id] = val;
    return;
  }
  int mid = (l + r) >> 1;
  modify2(idx, val, l, mid, id * 2 + 0);
  modify2(idx, val, mid, r, id * 2 + 1);
  seg2[id] = (seg2[id * 2 + 0] * seg2[id * 2 + 1]) % Mod;
  return;
}
long long int get2(int st, int en, int l = 0, int r = ((int)(vec).size()),
                   int id = 1) {
  if (st >= r or en <= l) return 1;
  if (st <= l and r <= en) return seg2[id];
  int mid = (l + r) >> 1;
  return (get2(st, en, l, mid, id * 2 + 0) * get2(st, en, mid, r, id * 2 + 1)) %
         Mod;
}
bool cmp(pair<pair<long long int, long long int>, long long int> x,
         pair<pair<long long int, long long int>, long long int> y) {
  return x.first.second < y.first.second;
}
void find_primes(void) {
  for (int i = 2; i < maxval; i++)
    if (facts[i].size() == 0)
      for (int j = i; j < maxval; j += i) facts[j].push_back(i);
  return;
}
long long int Pow(long long int x, long long int y) {
  long long int ret = 1, an = x;
  for (int i = 0; y; i++, an = (an * an) % Mod)
    if ((y >> i) & 1LL) ret = (ret * an) % Mod, y ^= (1LL << i);
  return ret;
}
long long int Div(long long int x, long long int y) {
  return (x * Pow(y, Mod - 2)) % Mod;
}
long long int Rev(long long int x) {
  if (rev_filled[x]) return rev[x];
  rev_filled[x] = true;
  return rev[x] = Div(1, x);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  memset(adss, -1, sizeof adss);
  find_primes();
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sttime[i] = ((int)(vec).size());
    for (auto f : facts[a[i]]) {
      last[((int)(vec).size())] = adss[f];
      adss[f] = ((int)(vec).size());
      vec.push_back(f);
    }
    fitime[i] = ((int)(vec).size());
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> quer[i].first.first >> quer[i].first.second;
    quer[i].first.first--;
    quer[i].second = i;
  }
  sort(quer, quer + q, cmp);
  build1();
  int p = 0;
  for (int i = 0; i < q; i++) {
    while (p < quer[i].first.second) {
      for (int j = sttime[p]; j < fitime[p]; j++) {
        modify2(last[j], 1);
        modify2(j, ((vec[j] - 1) * Rev(vec[j])) % Mod);
      }
      p++;
    }
    ans[quer[i].second] =
        (get1(quer[i].first.first, quer[i].first.second) *
         get2(sttime[quer[i].first.first], fitime[quer[i].first.second - 1])) %
        Mod;
  }
  for (int i = 0; i < q; i++) cout << ans[i] << '\n';
  return 0;
}

```