#include <bits/stdc++.h>
using namespace std;
int D[1000010];
vector<pair<int, int> > prim;
int wejscie[200001];
vector<pair<int, pair<int, int> > > Q;
vector<pair<int, int> > res;
vector<int> liczby[200001];
int znaczniki[1000001];
vector<int> pozycje[1000001];
int w = 262143;
int mod = 1000000007;
int drzewo[600000];
void sito(int n) {
  int dziel = 1;
  while (dziel * dziel <= n) {
    for (int i = dziel + 1; i <= n; i++) {
      if (D[i] == 0) {
        dziel = i;
        break;
      }
    }
    D[dziel] = dziel;
    for (int i = dziel * dziel; i <= n; i += dziel) {
      D[i] = dziel;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (D[i] == 0) D[i] = i;
  }
}
void rozklad(int a) {
  vector<int> v;
  while (a != 1) {
    v.push_back(D[a]);
    a /= D[a];
  }
  sort(v.begin(), v.end());
  int k = 1;
  for (int i = 1; i < v.size(); i++) {
    if (v[i] != v[i - 1]) {
      prim.push_back(make_pair(v[i - 1], k));
      k = 1;
    } else
      k++;
  }
  if (v.size() > 0) prim.push_back(make_pair(v[v.size() - 1], k));
  v.clear();
}
void push(int a, int pos) {
  pos += w;
  while (pos != 0) {
    if (drzewo[pos] == 0)
      drzewo[pos] = a;
    else {
      drzewo[pos] = 1LL * drzewo[pos] * a % mod;
    }
    pos /= 2;
  }
}
int pot(int a, int p) {
  if (p == 0) return 1;
  if (p == 1) return a;
  int x = pot(a, p / 2);
  if (p % 2 == 1) return (1LL * ((1LL * x * x) % mod) * a) % mod;
  return (1LL * x * x) % mod;
}
int odw(int a) { return pot(a, mod - 2); }
int przedzial(int pocz, int kon) {
  pocz += w;
  kon += w;
  int res = 1;
  while (pocz < kon) {
    if (pocz % 2 == 1) {
      res = (1LL * res * drzewo[pocz]) % mod;
      pocz++;
    }
    if (kon % 2 == 0) {
      res = (1LL * res * drzewo[kon]) % mod;
      kon--;
    }
    pocz /= 2;
    kon /= 2;
  }
  if (pocz == kon) res = (1LL * res * drzewo[pocz]) % mod;
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  int n, a;
  cin >> n;
  sito(1000000);
  for (int i = 1; i <= n; i++) {
    cin >> a;
    wejscie[i] = a;
    rozklad(a);
    for (int j = 0; j < prim.size(); j++) {
      liczby[i].push_back(prim[j].first);
      pozycje[prim[j].first].push_back(i);
    }
    prim.clear();
    push(a, i);
  }
  int q, l, r;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    cin >> l >> r;
    Q.push_back(make_pair(l, make_pair(r, i)));
  }
  for (int i = 1; i <= 1000000; i++) {
    if (pozycje[i].size() != 0) {
      int x = (1LL * (i - 1) * odw(i)) % mod;
      push(x, pozycje[i][0]);
    }
  }
  sort(Q.begin(), Q.end());
  int pos = 0;
  for (int i = 1; i <= n; i++) {
    while (Q[pos].first == i) {
      l = Q[pos].first;
      r = Q[pos].second.first;
      res.push_back(make_pair(Q[pos].second.second, przedzial(l, r)));
      pos++;
    }
    for (int j = 0; j < liczby[i].size(); j++) {
      int p = liczby[i][j];
      int x = (1LL * (p - 1) * odw(p)) % mod;
      int xodw = odw(x);
      push(xodw, pozycje[p][znaczniki[p]]);
      znaczniki[p]++;
      if (znaczniki[p] < pozycje[p].size()) push(x, pozycje[p][znaczniki[p]]);
    }
  }
  sort(res.begin(), res.end());
  for (int i = 0; i < res.size(); i++) cout << res[i].second << "\n";
}

### Prompt

Create a solution in cpp for 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;
int D[1000010];
vector<pair<int, int> > prim;
int wejscie[200001];
vector<pair<int, pair<int, int> > > Q;
vector<pair<int, int> > res;
vector<int> liczby[200001];
int znaczniki[1000001];
vector<int> pozycje[1000001];
int w = 262143;
int mod = 1000000007;
int drzewo[600000];
void sito(int n) {
  int dziel = 1;
  while (dziel * dziel <= n) {
    for (int i = dziel + 1; i <= n; i++) {
      if (D[i] == 0) {
        dziel = i;
        break;
      }
    }
    D[dziel] = dziel;
    for (int i = dziel * dziel; i <= n; i += dziel) {
      D[i] = dziel;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (D[i] == 0) D[i] = i;
  }
}
void rozklad(int a) {
  vector<int> v;
  while (a != 1) {
    v.push_back(D[a]);
    a /= D[a];
  }
  sort(v.begin(), v.end());
  int k = 1;
  for (int i = 1; i < v.size(); i++) {
    if (v[i] != v[i - 1]) {
      prim.push_back(make_pair(v[i - 1], k));
      k = 1;
    } else
      k++;
  }
  if (v.size() > 0) prim.push_back(make_pair(v[v.size() - 1], k));
  v.clear();
}
void push(int a, int pos) {
  pos += w;
  while (pos != 0) {
    if (drzewo[pos] == 0)
      drzewo[pos] = a;
    else {
      drzewo[pos] = 1LL * drzewo[pos] * a % mod;
    }
    pos /= 2;
  }
}
int pot(int a, int p) {
  if (p == 0) return 1;
  if (p == 1) return a;
  int x = pot(a, p / 2);
  if (p % 2 == 1) return (1LL * ((1LL * x * x) % mod) * a) % mod;
  return (1LL * x * x) % mod;
}
int odw(int a) { return pot(a, mod - 2); }
int przedzial(int pocz, int kon) {
  pocz += w;
  kon += w;
  int res = 1;
  while (pocz < kon) {
    if (pocz % 2 == 1) {
      res = (1LL * res * drzewo[pocz]) % mod;
      pocz++;
    }
    if (kon % 2 == 0) {
      res = (1LL * res * drzewo[kon]) % mod;
      kon--;
    }
    pocz /= 2;
    kon /= 2;
  }
  if (pocz == kon) res = (1LL * res * drzewo[pocz]) % mod;
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  int n, a;
  cin >> n;
  sito(1000000);
  for (int i = 1; i <= n; i++) {
    cin >> a;
    wejscie[i] = a;
    rozklad(a);
    for (int j = 0; j < prim.size(); j++) {
      liczby[i].push_back(prim[j].first);
      pozycje[prim[j].first].push_back(i);
    }
    prim.clear();
    push(a, i);
  }
  int q, l, r;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    cin >> l >> r;
    Q.push_back(make_pair(l, make_pair(r, i)));
  }
  for (int i = 1; i <= 1000000; i++) {
    if (pozycje[i].size() != 0) {
      int x = (1LL * (i - 1) * odw(i)) % mod;
      push(x, pozycje[i][0]);
    }
  }
  sort(Q.begin(), Q.end());
  int pos = 0;
  for (int i = 1; i <= n; i++) {
    while (Q[pos].first == i) {
      l = Q[pos].first;
      r = Q[pos].second.first;
      res.push_back(make_pair(Q[pos].second.second, przedzial(l, r)));
      pos++;
    }
    for (int j = 0; j < liczby[i].size(); j++) {
      int p = liczby[i][j];
      int x = (1LL * (p - 1) * odw(p)) % mod;
      int xodw = odw(x);
      push(xodw, pozycje[p][znaczniki[p]]);
      znaczniki[p]++;
      if (znaczniki[p] < pozycje[p].size()) push(x, pozycje[p][znaczniki[p]]);
    }
  }
  sort(res.begin(), res.end());
  for (int i = 0; i < res.size(); i++) cout << res[i].second << "\n";
}

```