#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9 + 7;
const long long MOD = 1e9 + 7;
const int N = 1e6 + 5;
const int M = 1e6 + 5;
const int K = 15;
int LE = 500;
int a[N];
int n, q;
int binpow(int x, int s) {
  if (s == 0) {
    return 1;
  }
  long long xx = binpow(x, s / 2);
  if ((s & 1) == 0) {
    return (xx * xx) % MOD;
  }
  return (((xx * xx) % MOD) * x) % MOD;
}
int d[M];
int sz[N];
int vn[N][K];
int cn[N][K];
int answer[N];
int inv[M];
int opti[M];
int opti2[M];
pair<pair<int, int>, int> za[N];
int ans = 1;
int cnt[N];
int pr[N];
inline void fact(int i) {
  int x = a[i];
  if (x == 1) return;
  vn[i][0] = d[x];
  cn[i][0] = 1;
  sz[i] = 1;
  x /= d[x];
  while (x > 1) {
    if (d[x] != vn[i][sz[i] - 1]) {
      vn[i][sz[i]] = d[x];
      cn[i][sz[i]] = 1;
      sz[i]++;
    } else {
      cn[i][sz[i] - 1]++;
    }
    x /= d[x];
  }
}
bool cmp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {
  if (a.first.first / LE == b.first.first / LE) {
    if ((a.first.first / LE) & 1)
      return a.first.second > b.first.second;
    else
      return a.first.second < b.first.second;
  }
  return a.first.first < b.first.first;
}
int main() {
  d[1] = 1;
  for (int i = 2; i < M; i++) {
    if (d[i]) continue;
    d[i] = i;
    if (i * 1LL * i < 1LL * M) {
      for (int j = i * i; j < M; j += i) {
        d[j] = i;
      }
    }
  }
  for (int i = 1; i < M; i++) {
    inv[i] = binpow(i, MOD - 2);
  }
  for (int i = 1; i < M; i++) {
    long long mi = (i - 1);
    mi %= MOD;
    mi *= inv[i];
    mi %= MOD;
    opti[i] = mi;
    mi = i;
    mi %= MOD;
    mi *= inv[i - 1];
    mi %= MOD;
    opti2[i] = mi;
  }
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    pr[i] = a[i];
    if (i) pr[i] = ((long long)pr[i] * pr[i - 1]) % MOD;
    fact(i);
  }
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    l--;
    r--;
    za[i] = make_pair(make_pair(l, r), i);
  }
  sort(za, za + q, cmp);
  int L = 0;
  int R = -1;
  ans = 1;
  for (int i = 0; i < q; i++) {
    int l = za[i].first.first;
    int r = za[i].first.second;
    while (R < r) {
      R++;
      for (int i = 0; i < sz[R]; i++) {
        if (cnt[vn[R][i]] == 0) {
          ans = ((long long)ans * opti[vn[R][i]]) % MOD;
        }
        cnt[vn[R][i]] += cn[R][i];
      }
    }
    while (L > l) {
      L--;
      for (int i = 0; i < sz[L]; i++) {
        if (cnt[vn[L][i]] == 0) {
          ans = ((long long)ans * opti[vn[L][i]]) % MOD;
        }
        cnt[vn[L][i]] += cn[L][i];
      }
    }
    while (L < l) {
      for (int i = 0; i < sz[L]; i++) {
        cnt[vn[L][i]] -= cn[L][i];
        if (cnt[vn[L][i]] == 0) {
          ans = ((long long)ans * opti2[vn[L][i]]) % MOD;
        }
      }
      L++;
    }
    while (R > r) {
      for (int i = 0; i < sz[R]; i++) {
        cnt[vn[R][i]] -= cn[R][i];
        if (cnt[vn[R][i]] == 0) {
          ans = ((long long)ans * opti2[vn[R][i]]) % MOD;
        }
      }
      R--;
    }
    long long LOL = pr[R];
    if (L != 0) LOL = (LOL * binpow(pr[L - 1], MOD - 2)) % MOD;
    answer[za[i].second] = (ans * LOL) % MOD;
  }
  for (int i = 0; i < q; i++) printf("%d\n", answer[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;
const int INF = 2e9 + 7;
const long long MOD = 1e9 + 7;
const int N = 1e6 + 5;
const int M = 1e6 + 5;
const int K = 15;
int LE = 500;
int a[N];
int n, q;
int binpow(int x, int s) {
  if (s == 0) {
    return 1;
  }
  long long xx = binpow(x, s / 2);
  if ((s & 1) == 0) {
    return (xx * xx) % MOD;
  }
  return (((xx * xx) % MOD) * x) % MOD;
}
int d[M];
int sz[N];
int vn[N][K];
int cn[N][K];
int answer[N];
int inv[M];
int opti[M];
int opti2[M];
pair<pair<int, int>, int> za[N];
int ans = 1;
int cnt[N];
int pr[N];
inline void fact(int i) {
  int x = a[i];
  if (x == 1) return;
  vn[i][0] = d[x];
  cn[i][0] = 1;
  sz[i] = 1;
  x /= d[x];
  while (x > 1) {
    if (d[x] != vn[i][sz[i] - 1]) {
      vn[i][sz[i]] = d[x];
      cn[i][sz[i]] = 1;
      sz[i]++;
    } else {
      cn[i][sz[i] - 1]++;
    }
    x /= d[x];
  }
}
bool cmp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {
  if (a.first.first / LE == b.first.first / LE) {
    if ((a.first.first / LE) & 1)
      return a.first.second > b.first.second;
    else
      return a.first.second < b.first.second;
  }
  return a.first.first < b.first.first;
}
int main() {
  d[1] = 1;
  for (int i = 2; i < M; i++) {
    if (d[i]) continue;
    d[i] = i;
    if (i * 1LL * i < 1LL * M) {
      for (int j = i * i; j < M; j += i) {
        d[j] = i;
      }
    }
  }
  for (int i = 1; i < M; i++) {
    inv[i] = binpow(i, MOD - 2);
  }
  for (int i = 1; i < M; i++) {
    long long mi = (i - 1);
    mi %= MOD;
    mi *= inv[i];
    mi %= MOD;
    opti[i] = mi;
    mi = i;
    mi %= MOD;
    mi *= inv[i - 1];
    mi %= MOD;
    opti2[i] = mi;
  }
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    pr[i] = a[i];
    if (i) pr[i] = ((long long)pr[i] * pr[i - 1]) % MOD;
    fact(i);
  }
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    l--;
    r--;
    za[i] = make_pair(make_pair(l, r), i);
  }
  sort(za, za + q, cmp);
  int L = 0;
  int R = -1;
  ans = 1;
  for (int i = 0; i < q; i++) {
    int l = za[i].first.first;
    int r = za[i].first.second;
    while (R < r) {
      R++;
      for (int i = 0; i < sz[R]; i++) {
        if (cnt[vn[R][i]] == 0) {
          ans = ((long long)ans * opti[vn[R][i]]) % MOD;
        }
        cnt[vn[R][i]] += cn[R][i];
      }
    }
    while (L > l) {
      L--;
      for (int i = 0; i < sz[L]; i++) {
        if (cnt[vn[L][i]] == 0) {
          ans = ((long long)ans * opti[vn[L][i]]) % MOD;
        }
        cnt[vn[L][i]] += cn[L][i];
      }
    }
    while (L < l) {
      for (int i = 0; i < sz[L]; i++) {
        cnt[vn[L][i]] -= cn[L][i];
        if (cnt[vn[L][i]] == 0) {
          ans = ((long long)ans * opti2[vn[L][i]]) % MOD;
        }
      }
      L++;
    }
    while (R > r) {
      for (int i = 0; i < sz[R]; i++) {
        cnt[vn[R][i]] -= cn[R][i];
        if (cnt[vn[R][i]] == 0) {
          ans = ((long long)ans * opti2[vn[R][i]]) % MOD;
        }
      }
      R--;
    }
    long long LOL = pr[R];
    if (L != 0) LOL = (LOL * binpow(pr[L - 1], MOD - 2)) % MOD;
    answer[za[i].second] = (ans * LOL) % MOD;
  }
  for (int i = 0; i < q; i++) printf("%d\n", answer[i]);
  return 0;
}

```