#include <map>
#include <iostream>
#include <fstream>

using namespace std;
using namespace std::tr1;

int main()
{
    ifstream in("elections.in");
    ofstream out("elections.out");
    int n;
    in >> n;
    int *a = new int[n];
    for (int i = 0; i < n; i++)
        in >> a[i];
    int m;
    in >> m;
    for (int i = 0; i < m; i++)
    {
        int left, right;
        in >> left >> right;
        map<int, int> b;
        for (int j = left - 1; j < right; j++)
            b[a[j]]++;
        int ans = -1;
        int sz = 0;
        for (unordered_map<int, int>::const_iterator p = b.begin(); p != b.end(); p++)
            if (p->second > sz)
            {
                sz = p->second;
                ans = p->first;
            }
        out <</* ans << " " << */sz << "\n";
    }
}
