#include <cstdio>
#include <map>
#include <algorithm>
#include <cassert>

using namespace std;

const int maxn = 5;

int n, q;
int a[maxn];

inline bool bit(int msk, int i)
{
  return msk & (1 << i);
}

inline int mex(int msk, int n, int add)
{     
  map <int, bool> have;
  for (int i = 0; i < n; i++)
    if (bit(msk, i))
      have[a[i + add]] = 1;
  int ans;
  for (ans = 1;; ans++)
    if (!have[ans])
      return ans;
  return -1;
}      

int main()
{
  freopen("bumblebee.in", "r", stdin);
  freopen("bumblebee.out", "w", stdout);
  scanf("%d", &n);
  assert(n <= 4);
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  scanf("%d", &q);
  for (int i = 0; i < q; i++)
  {
    int l, r;
    scanf("%d%d", &l, &r);
    --l, --r;
    int len = r - l + 1;
    int ans = 0;
    for (int msk = 1; msk < (1 << len); msk++)
    {
      int x = mex(msk, len, l);
      ans = __gcd(ans, x);
    }
    printf("%d\n", ans);
  }       
}
