#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
const long long MOD = 1000000007;
const int MAX_N = 200011;
const int MAX_Q = 200011;
const int MAX_A = 1000011;
int Arr[MAX_A];
int A[MAX_N], L[MAX_Q], R[MAX_Q];
long long D[MAX_Q];
bool solved[MAX_Q];
int cc[MAX_A];
int sum[MAX_N];
vector<int> gogo[MAX_N];
long long THRESHOLD = 1000;
int main() {
  int cnt = 0;
  for (int i = 2; i <= 1000000; i++) {
    int w = -1;
    for (int j = 2; j * j <= i; j++) {
      if (i % j == 0) {
        w = j;
        break;
      }
    }
    Arr[i] = w;
    if (w == -1) cnt++;
  }
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &A[i]);
  }
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d %d", &L[i], &R[i]);
    L[i]--;
    R[i]--;
    D[i] = 1;
  }
  for (int i = 2; i <= THRESHOLD; i++) {
    if (Arr[i] == -1) {
      for (int j = 0; j < n; j++) {
        sum[j] = 0;
        while (A[j] % i == 0) {
          A[j] /= i;
          sum[j]++;
        }
        if (j > 0) sum[j] += sum[j - 1];
      }
      long long *w = new long long[sum[n - 1] + 1];
      w[0] = 1;
      for (int j = 1; j <= sum[n - 1]; j++) {
        w[j] = (w[j - 1] * (long long)i) % MOD;
      }
      for (int j = 0; j < q; j++) {
        int ss = sum[R[j]];
        if (L[j] > 0) {
          ss -= sum[L[j] - 1];
        }
        if (ss > 0) {
          D[j] = (D[j] * (long long)(i - 1)) % MOD;
          D[j] = (D[j] * (long long)w[ss - 1]) % MOD;
        }
      }
      delete[] w;
    }
  }
  const int sqn = 400;
  for (int i = 0; i < q; i++) {
    if (R[i] - L[i] <= sqn) {
      for (int j = L[i]; j <= R[i]; j++) {
        if (A[j] > 1) {
          cc[A[j]]++;
          if (cc[A[j]] == 1) {
            D[i] = (D[i] * (long long)(A[j] - 1)) % MOD;
          } else {
            D[i] = (D[i] * (long long)(A[j])) % MOD;
          }
        }
      }
      for (int j = L[i]; j <= R[i]; j++) {
        if (A[j] > 1) {
          cc[A[j]]--;
        }
      }
      solved[i] = true;
    }
  }
  for (int i = sqn; i < n; i += sqn) {
    for (int j = 0; j < q; j++) {
      if (!solved[j] && i - sqn <= L[j] && L[j] <= i) {
        gogo[R[j]].push_back(j);
      }
    }
    long long mult = 1;
    for (int t = i; t < n; t++) {
      if (A[t] > 1) {
        cc[A[t]]++;
        if (cc[A[t]] == 1) {
          mult = (mult * (long long)(A[t] - 1)) % MOD;
        } else {
          mult = (mult * (long long)A[t]) % MOD;
        }
      }
      if (gogo[t].size() > 0) {
        for (int w = 0; w < (int)gogo[t].size(); w++) {
          int g = gogo[t][w];
          long long tmult = mult;
          for (int u = i - 1; u >= L[g]; u--) {
            if (A[u] > 1) {
              cc[A[u]]++;
              if (cc[A[u]] == 1) {
                tmult = (tmult * (long long)(A[u] - 1)) % MOD;
              } else {
                tmult = (tmult * (long long)A[u]) % MOD;
              }
            }
          }
          for (int u = i - 1; u >= L[g]; u--) {
            if (A[u] > 1) {
              cc[A[u]]--;
            }
          }
          D[g] = (D[g] * tmult) % MOD;
        }
      }
    }
    for (int t = i; t < n; t++) {
      if (A[t] > 1) {
        cc[A[t]]--;
      }
    }
    for (int j = 0; j < q; j++) {
      if (!solved[j] && i - sqn <= L[j] && L[j] <= i) {
        solved[j] = true;
        gogo[R[j]].clear();
      }
    }
  }
  for (int i = 0; i < q; i++) {
    printf("%I64d\n", D[i]);
  }
  return 0;
}
