#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
long long mypow(long long a, long long p){
if(p == 0) return 1;
if(p == 1) return (a % MOD);
if(p & 1) return ((a % MOD) * (mypow(a, p - 1) % MOD)) % MOD;
long long x = mypow(a, p / 2) % MOD;
return (x * x) % MOD;
}
long long inv(long long base){
return mypow(base, MOD - 2);
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<long long> a(n + 1);
for(int i = 1; i <= n; i++) cin >> a[i];
vector<long long> mult(n + 1);
mult[0] = 1LL;
vector<long long> mult1(n + 1);
mult1[0] = 1LL;
vector<int> z, z1;
for(int i = 1; i <= n; i++){
if(i & 1){
if(a[i]) mult[i] = (1LL * mult[i - 1] * a[i]) % MOD;
else{
mult[i] = mult[i - 1];
z.push_back(i);
}
mult1[i] = mult1[i - 1];
}
else{
if(a[i]) mult1[i] = (1LL * mult1[i - 1] * a[i]) % MOD;
else{
mult1[i] = mult1[i - 1];
z1.push_back(i);
}
mult[i] = mult[i - 1];
}
}
int q;
cin >> q;
for(int i = 0; i < q; i++){
int l, r;
cin >> l >> r;
if(l & 1){
if(z.size()){
int p = lower_bound(z.begin(), z.end(), l) - z.begin();
if(z[p] <= r && z[p] >= l){
cout << 0 << endl;
continue;
}
}
cout << (long long)(1LL * mult[r] * inv(mult[l - 1]) % MOD) << '\n';
}
else{
if(z1.size()){
int p = lower_bound(z1.begin(), z1.end(), l) - z1.begin();
if(z1[p] <= r && z1[p] >= l){
cout << 0 << endl;
continue;
}
}
cout << (long long)(1LL * mult1[r] * inv(mult1[l - 1]) % MOD) << '\n';
}
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmNvbnN0IGludCBNT0QgPSAxZTkgKyA3OwoKbG9uZyBsb25nIG15cG93KGxvbmcgbG9uZyBhLCBsb25nIGxvbmcgcCl7CglpZihwID09IDApIHJldHVybiAxOwoJaWYocCA9PSA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