#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265359;
const double E = 2.718281828459;
const long long int MOD = 1000000007;
long long int a[1000002];
bool primes[1000002];
long long int primos[1000002], fenwick[1000002];
vector<int> fact[1000002];
vector<int> queries[200002];
map<pair<int, int>, long long int> result;
int Next[200002][20], FO[1000002];
map<int, int> current;
pair<int, int> Truequerie[200002];
inline long long int binpow(long long int a, long long int n) {
  if (n == 0) return 1;
  if (n & 1) {
    return (a * binpow(a, n - 1)) % MOD;
  }
  long long int ans = binpow(a, n / 2);
  return (ans * ans) % MOD;
}
void add(int idx, long long int val) {
  while (idx < 1000002) {
    fenwick[idx] = (fenwick[idx] * val) % MOD;
    idx += (idx & -idx);
  }
}
long long int RecoveryFreq(int idx) {
  long long int sum = 1;
  while (idx > 0) {
    sum = (sum * fenwick[idx]) % MOD;
    idx -= (idx & -idx);
  }
  return sum;
}
inline long long int inv(long long int n) { return binpow(n, MOD - 2); }
int main() {
  ios::sync_with_stdio(false);
  ;
  int n;
  cin >> n;
  primes[0] = primes[1] = 1;
  primes[2] = 0;
  for (int i = 3; i * i <= 1000002; i += 2) {
    if (!primes[i]) {
      for (int j = 3 * i; j < 1000002; j += (i << 1)) primes[j] = 1;
    }
  }
  primos[0] = 2;
  int cont = 1;
  for (int i = 3; i < 1000002; i += 2)
    if (!primes[i]) primos[cont++] = i;
  for (int i = 0; i < cont; ++i) {
    for (int j = primos[i]; j < 1000002; j += primos[i]) fact[j].push_back(i);
  }
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < cont; ++i) FO[i] = -1;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < fact[a[i]].size(); ++j) {
      if (FO[fact[a[i]][j]] == -1) {
        FO[fact[a[i]][j]] = i + 1;
      }
    }
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 0; j < 20; ++j) Next[i][j] = -1;
  int ptemp, nextemp, ttemp;
  long long int temp;
  for (int i = n; i >= 1; --i) {
    for (int j = 0; j < fact[a[i - 1]].size(); ++j) {
      ttemp = fact[a[i - 1]][j];
      if (!current.count(ttemp)) {
        current[ttemp] = i;
      } else {
        Next[i][j] = current[ttemp];
        current[ttemp] = i;
      }
    }
  }
  for (int i = 1; i < 1000002; ++i) fenwick[i] = 1;
  for (int i = 1; i <= n; ++i) add(i, a[i - 1]);
  for (int i = 0; i < cont; ++i) {
    if (FO[i] != -1) {
      temp = ((primos[i] - 1) * inv(primos[i])) % MOD;
      add(FO[i], temp);
    }
  }
  int q;
  cin >> q;
  int r, l;
  long long int ans;
  for (int i = 0; i < q; ++i) {
    cin >> l >> r;
    Truequerie[i] = make_pair((l), (r));
    queries[l].push_back(r);
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < queries[i].size(); ++j) {
      if (result.count({i, queries[i][j]})) continue;
      ans = (RecoveryFreq(queries[i][j]) * inv(RecoveryFreq(i - 1))) % MOD;
      result[{i, queries[i][j]}] = ans;
    }
    for (int j = 0; j < fact[a[i - 1]].size(); ++j) {
      nextemp = Next[i][j];
      ptemp = primos[fact[a[i - 1]][j]];
      if (nextemp != -1) {
        add(nextemp, ((ptemp - 1) * inv(ptemp)) % MOD);
      }
    }
  }
  int extL, extR;
  for (int i = 0; i < q; ++i) {
    extL = Truequerie[i].first, extR = Truequerie[i].second;
    cout << result[{extL, extR}] << endl;
  }
  return 0;
}

### Prompt

Your task is to create 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 double PI = 3.14159265359;
const double E = 2.718281828459;
const long long int MOD = 1000000007;
long long int a[1000002];
bool primes[1000002];
long long int primos[1000002], fenwick[1000002];
vector<int> fact[1000002];
vector<int> queries[200002];
map<pair<int, int>, long long int> result;
int Next[200002][20], FO[1000002];
map<int, int> current;
pair<int, int> Truequerie[200002];
inline long long int binpow(long long int a, long long int n) {
  if (n == 0) return 1;
  if (n & 1) {
    return (a * binpow(a, n - 1)) % MOD;
  }
  long long int ans = binpow(a, n / 2);
  return (ans * ans) % MOD;
}
void add(int idx, long long int val) {
  while (idx < 1000002) {
    fenwick[idx] = (fenwick[idx] * val) % MOD;
    idx += (idx & -idx);
  }
}
long long int RecoveryFreq(int idx) {
  long long int sum = 1;
  while (idx > 0) {
    sum = (sum * fenwick[idx]) % MOD;
    idx -= (idx & -idx);
  }
  return sum;
}
inline long long int inv(long long int n) { return binpow(n, MOD - 2); }
int main() {
  ios::sync_with_stdio(false);
  ;
  int n;
  cin >> n;
  primes[0] = primes[1] = 1;
  primes[2] = 0;
  for (int i = 3; i * i <= 1000002; i += 2) {
    if (!primes[i]) {
      for (int j = 3 * i; j < 1000002; j += (i << 1)) primes[j] = 1;
    }
  }
  primos[0] = 2;
  int cont = 1;
  for (int i = 3; i < 1000002; i += 2)
    if (!primes[i]) primos[cont++] = i;
  for (int i = 0; i < cont; ++i) {
    for (int j = primos[i]; j < 1000002; j += primos[i]) fact[j].push_back(i);
  }
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < cont; ++i) FO[i] = -1;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < fact[a[i]].size(); ++j) {
      if (FO[fact[a[i]][j]] == -1) {
        FO[fact[a[i]][j]] = i + 1;
      }
    }
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 0; j < 20; ++j) Next[i][j] = -1;
  int ptemp, nextemp, ttemp;
  long long int temp;
  for (int i = n; i >= 1; --i) {
    for (int j = 0; j < fact[a[i - 1]].size(); ++j) {
      ttemp = fact[a[i - 1]][j];
      if (!current.count(ttemp)) {
        current[ttemp] = i;
      } else {
        Next[i][j] = current[ttemp];
        current[ttemp] = i;
      }
    }
  }
  for (int i = 1; i < 1000002; ++i) fenwick[i] = 1;
  for (int i = 1; i <= n; ++i) add(i, a[i - 1]);
  for (int i = 0; i < cont; ++i) {
    if (FO[i] != -1) {
      temp = ((primos[i] - 1) * inv(primos[i])) % MOD;
      add(FO[i], temp);
    }
  }
  int q;
  cin >> q;
  int r, l;
  long long int ans;
  for (int i = 0; i < q; ++i) {
    cin >> l >> r;
    Truequerie[i] = make_pair((l), (r));
    queries[l].push_back(r);
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < queries[i].size(); ++j) {
      if (result.count({i, queries[i][j]})) continue;
      ans = (RecoveryFreq(queries[i][j]) * inv(RecoveryFreq(i - 1))) % MOD;
      result[{i, queries[i][j]}] = ans;
    }
    for (int j = 0; j < fact[a[i - 1]].size(); ++j) {
      nextemp = Next[i][j];
      ptemp = primos[fact[a[i - 1]][j]];
      if (nextemp != -1) {
        add(nextemp, ((ptemp - 1) * inv(ptemp)) % MOD);
      }
    }
  }
  int extL, extR;
  for (int i = 0; i < q; ++i) {
    extL = Truequerie[i].first, extR = Truequerie[i].second;
    cout << result[{extL, extR}] << endl;
  }
  return 0;
}

```