#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > query[200005];
long long int nums[200005], cumumlative[200005], result[200005],
    mod_inverse[1000005], tree[4 * 200005];
int prime[1000005], greatest_prime_factor[1000005], last_location[1000005];
long long int pwr(long long int x, long long int y) {
  if (y == 0) return 1LL;
  long long int temp = pwr(x, y / 2);
  temp = (temp * temp);
  if (temp >= 1000000007LL) temp = temp % 1000000007LL;
  if (y % 2) return (temp * x) % 1000000007LL;
  return temp;
}
void sieve() {
  int i, j;
  for (i = 2; i < 1005; i++) {
    if (prime[i] == 0) {
      for (j = i * i; j < 1000005; j += i) {
        prime[j] = 1;
        greatest_prime_factor[j] = i;
      }
    }
  }
  mod_inverse[1] = 1LL;
  for (i = 2; i < 1000005; i++) {
    last_location[i] = -1;
    mod_inverse[i] = pwr(i, 1000000007LL - 2LL);
  }
  return;
}
long long int half(long long int q, long long int w) { return q + (w - q) / 2; }
long long int get_product(long long int left, long long int right,
                          long long int current, long long int q_left,
                          long long int q_right) {
  if (q_left <= left && q_right >= right) return tree[current];
  if (q_left > right || q_right < left) return 1LL;
  long long int mid = half(left, right);
  long long int temp =
      get_product(left, mid, 2 * current + 1, q_left, q_right) *
      get_product(mid + 1, right, 2 * current + 2, q_left, q_right);
  if (temp >= 1000000007LL) temp = temp % 1000000007LL;
  return temp;
}
long long int update(long long int left, long long int right,
                     long long int current, long long int change,
                     long long int index) {
  if (index < left || index > right) return tree[current];
  if (left == right) {
    tree[current] = (tree[current] * change) % 1000000007LL;
    return tree[current];
  }
  long long int mid = half(left, right);
  tree[current] = update(left, mid, 2 * current + 1, change, index) *
                  update(mid + 1, right, 2 * current + 2, change, index);
  if (tree[current] >= 1000000007LL)
    tree[current] = tree[current] % 1000000007LL;
  return tree[current];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  int i, j, t, n, m, k, l, r, temp, mini, maxi, flag, prime_factor;
  pair<int, int> node;
  long long int product, bar, update_required;
  for (i = 0; i < 4 * 200005; i++) tree[i] = 1LL;
  sieve();
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> nums[i];
    if (i == 0)
      cumumlative[i] = nums[i];
    else
      cumumlative[i] = cumumlative[i - 1] * nums[i];
    if (cumumlative[i] >= 1000000007LL)
      cumumlative[i] = cumumlative[i] % 1000000007LL;
  }
  cin >> m;
  for (i = 0; i < m; i++) {
    cin >> l >> r;
    query[r - 1].push_back(make_pair(l - 1, i));
  }
  for (i = 0; i < n; i++) {
    update_required = 1LL;
    temp = nums[i];
    while (temp != 1) {
      if (prime[temp] == 0)
        prime_factor = temp;
      else
        prime_factor = greatest_prime_factor[temp];
      while (temp != 1 && temp % prime_factor == 0) temp /= prime_factor;
      update_required =
          (((long long int)prime_factor - 1LL) * (mod_inverse[prime_factor])) %
          1000000007LL;
      if (update_required >= 1000000007LL)
        update_required = update_required % 1000000007LL;
      bar = update(0, n - 1, 0, update_required, i);
      if (last_location[prime_factor] != -1) {
        update_required =
            ((long long int)prime_factor * mod_inverse[prime_factor - 1]);
        if (update_required >= 1000000007LL)
          update_required = update_required % 1000000007LL;
        bar = update(0, n - 1, 0, update_required, last_location[prime_factor]);
      }
      last_location[prime_factor] = i;
    }
    for (j = 0; j < query[i].size(); j++) {
      node = query[i][j];
      if (node.first == 0)
        product = cumumlative[i];
      else
        product = (cumumlative[i] *
                   pwr(cumumlative[node.first - 1], 1000000007LL - 2LL)) %
                  1000000007LL;
      result[node.second] = get_product(0, n - 1, 0, node.first, i);
      result[node.second] = result[node.second] * product;
      if (result[node.second] >= 1000000007LL)
        result[node.second] = result[node.second] % 1000000007LL;
    }
  }
  for (i = 0; i < m; i++) cout << result[i] << endl;
  return 0;
}

### Prompt

Generate 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;
vector<pair<int, int> > query[200005];
long long int nums[200005], cumumlative[200005], result[200005],
    mod_inverse[1000005], tree[4 * 200005];
int prime[1000005], greatest_prime_factor[1000005], last_location[1000005];
long long int pwr(long long int x, long long int y) {
  if (y == 0) return 1LL;
  long long int temp = pwr(x, y / 2);
  temp = (temp * temp);
  if (temp >= 1000000007LL) temp = temp % 1000000007LL;
  if (y % 2) return (temp * x) % 1000000007LL;
  return temp;
}
void sieve() {
  int i, j;
  for (i = 2; i < 1005; i++) {
    if (prime[i] == 0) {
      for (j = i * i; j < 1000005; j += i) {
        prime[j] = 1;
        greatest_prime_factor[j] = i;
      }
    }
  }
  mod_inverse[1] = 1LL;
  for (i = 2; i < 1000005; i++) {
    last_location[i] = -1;
    mod_inverse[i] = pwr(i, 1000000007LL - 2LL);
  }
  return;
}
long long int half(long long int q, long long int w) { return q + (w - q) / 2; }
long long int get_product(long long int left, long long int right,
                          long long int current, long long int q_left,
                          long long int q_right) {
  if (q_left <= left && q_right >= right) return tree[current];
  if (q_left > right || q_right < left) return 1LL;
  long long int mid = half(left, right);
  long long int temp =
      get_product(left, mid, 2 * current + 1, q_left, q_right) *
      get_product(mid + 1, right, 2 * current + 2, q_left, q_right);
  if (temp >= 1000000007LL) temp = temp % 1000000007LL;
  return temp;
}
long long int update(long long int left, long long int right,
                     long long int current, long long int change,
                     long long int index) {
  if (index < left || index > right) return tree[current];
  if (left == right) {
    tree[current] = (tree[current] * change) % 1000000007LL;
    return tree[current];
  }
  long long int mid = half(left, right);
  tree[current] = update(left, mid, 2 * current + 1, change, index) *
                  update(mid + 1, right, 2 * current + 2, change, index);
  if (tree[current] >= 1000000007LL)
    tree[current] = tree[current] % 1000000007LL;
  return tree[current];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  int i, j, t, n, m, k, l, r, temp, mini, maxi, flag, prime_factor;
  pair<int, int> node;
  long long int product, bar, update_required;
  for (i = 0; i < 4 * 200005; i++) tree[i] = 1LL;
  sieve();
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> nums[i];
    if (i == 0)
      cumumlative[i] = nums[i];
    else
      cumumlative[i] = cumumlative[i - 1] * nums[i];
    if (cumumlative[i] >= 1000000007LL)
      cumumlative[i] = cumumlative[i] % 1000000007LL;
  }
  cin >> m;
  for (i = 0; i < m; i++) {
    cin >> l >> r;
    query[r - 1].push_back(make_pair(l - 1, i));
  }
  for (i = 0; i < n; i++) {
    update_required = 1LL;
    temp = nums[i];
    while (temp != 1) {
      if (prime[temp] == 0)
        prime_factor = temp;
      else
        prime_factor = greatest_prime_factor[temp];
      while (temp != 1 && temp % prime_factor == 0) temp /= prime_factor;
      update_required =
          (((long long int)prime_factor - 1LL) * (mod_inverse[prime_factor])) %
          1000000007LL;
      if (update_required >= 1000000007LL)
        update_required = update_required % 1000000007LL;
      bar = update(0, n - 1, 0, update_required, i);
      if (last_location[prime_factor] != -1) {
        update_required =
            ((long long int)prime_factor * mod_inverse[prime_factor - 1]);
        if (update_required >= 1000000007LL)
          update_required = update_required % 1000000007LL;
        bar = update(0, n - 1, 0, update_required, last_location[prime_factor]);
      }
      last_location[prime_factor] = i;
    }
    for (j = 0; j < query[i].size(); j++) {
      node = query[i][j];
      if (node.first == 0)
        product = cumumlative[i];
      else
        product = (cumumlative[i] *
                   pwr(cumumlative[node.first - 1], 1000000007LL - 2LL)) %
                  1000000007LL;
      result[node.second] = get_product(0, n - 1, 0, node.first, i);
      result[node.second] = result[node.second] * product;
      if (result[node.second] >= 1000000007LL)
        result[node.second] = result[node.second] % 1000000007LL;
    }
  }
  for (i = 0; i < m; i++) cout << result[i] << endl;
  return 0;
}

```