#include <bits/stdc++.h>
using namespace std;
int n;
int vis[1100000];
long long int primes[1100000];
bool isPrime[1100000];
int tot = 0;
long long int a[1100000];
long long int inv[1100000];
vector<int> query[1100000], id[1100000];
long long int BIT[1100000];
void BITupdate(int x, long long int mulv) {
  while (x <= n) {
    BIT[x] = (BIT[x] * mulv) % 1000000007;
    x += ((x) & (-(x)));
  }
}
long long int BITquery(int x) {
  long long int ans = 1;
  while (x) {
    ans = (ans * BIT[x]) % 1000000007;
    x -= ((x) & (-(x)));
  }
  return ans;
}
long long int fastPow(long long int base, long long int pow) {
  long long int ans = 1;
  while (pow) {
    if (pow & 1) ans = ans * base % 1000000007;
    base = base * base % 1000000007;
    pow >>= 1;
  }
  return ans;
}
long long int rev(long long int a) { return fastPow(a, 1000000007 - 2); }
void Sieve() {
  memset(isPrime, true, sizeof(isPrime));
  for (int i = 2; i < 1100000; i++) {
    if (isPrime[i]) primes[++tot] = i;
    for (int j = 1; j <= tot && i * primes[j] < 1100000; j++) {
      isPrime[i * primes[j]] = false;
      if (i % primes[j] == 0) break;
    }
  }
}
long long int sol[1100000];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]), BIT[i] = 1;
  int q;
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int L, R;
    scanf("%d%d", &L, &R);
    query[L].push_back(R);
    id[L].push_back(i);
  }
  for (int i = n; i >= 1; i--) {
    BITupdate(i, a[i]);
    long long int tmp = a[i];
    for (long long int x = 2; x * x <= tmp; x++)
      if (tmp % x == 0) {
        if (!vis[x])
          vis[x] = i;
        else {
          BITupdate(vis[x], rev((x - 1) * rev(x) % 1000000007));
          vis[x] = i;
        }
        BITupdate(i, (x - 1) * rev(x) % 1000000007);
        while (tmp % x == 0) tmp /= x;
      }
    if (tmp != 1) {
      if (!vis[tmp])
        vis[tmp] = i;
      else {
        BITupdate(vis[tmp], rev(tmp - 1) * tmp % 1000000007);
        vis[tmp] = i;
      }
      BITupdate(i, (tmp - 1) * rev(tmp) % 1000000007);
    }
    for (int j = 0; j < query[i].size(); j++)
      sol[id[i][j]] = BITquery(query[i][j]);
  }
  for (int i = 1; i <= q; i++) printf("%I64d\n", sol[i]);
  return 0;
}

### Prompt

Please formulate 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;
int n;
int vis[1100000];
long long int primes[1100000];
bool isPrime[1100000];
int tot = 0;
long long int a[1100000];
long long int inv[1100000];
vector<int> query[1100000], id[1100000];
long long int BIT[1100000];
void BITupdate(int x, long long int mulv) {
  while (x <= n) {
    BIT[x] = (BIT[x] * mulv) % 1000000007;
    x += ((x) & (-(x)));
  }
}
long long int BITquery(int x) {
  long long int ans = 1;
  while (x) {
    ans = (ans * BIT[x]) % 1000000007;
    x -= ((x) & (-(x)));
  }
  return ans;
}
long long int fastPow(long long int base, long long int pow) {
  long long int ans = 1;
  while (pow) {
    if (pow & 1) ans = ans * base % 1000000007;
    base = base * base % 1000000007;
    pow >>= 1;
  }
  return ans;
}
long long int rev(long long int a) { return fastPow(a, 1000000007 - 2); }
void Sieve() {
  memset(isPrime, true, sizeof(isPrime));
  for (int i = 2; i < 1100000; i++) {
    if (isPrime[i]) primes[++tot] = i;
    for (int j = 1; j <= tot && i * primes[j] < 1100000; j++) {
      isPrime[i * primes[j]] = false;
      if (i % primes[j] == 0) break;
    }
  }
}
long long int sol[1100000];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]), BIT[i] = 1;
  int q;
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int L, R;
    scanf("%d%d", &L, &R);
    query[L].push_back(R);
    id[L].push_back(i);
  }
  for (int i = n; i >= 1; i--) {
    BITupdate(i, a[i]);
    long long int tmp = a[i];
    for (long long int x = 2; x * x <= tmp; x++)
      if (tmp % x == 0) {
        if (!vis[x])
          vis[x] = i;
        else {
          BITupdate(vis[x], rev((x - 1) * rev(x) % 1000000007));
          vis[x] = i;
        }
        BITupdate(i, (x - 1) * rev(x) % 1000000007);
        while (tmp % x == 0) tmp /= x;
      }
    if (tmp != 1) {
      if (!vis[tmp])
        vis[tmp] = i;
      else {
        BITupdate(vis[tmp], rev(tmp - 1) * tmp % 1000000007);
        vis[tmp] = i;
      }
      BITupdate(i, (tmp - 1) * rev(tmp) % 1000000007);
    }
    for (int j = 0; j < query[i].size(); j++)
      sol[id[i][j]] = BITquery(query[i][j]);
  }
  for (int i = 1; i <= q; i++) printf("%I64d\n", sol[i]);
  return 0;
}

```