#include <bits/stdc++.h>
using namespace std;
ifstream fin("distincte.in");
ofstream fout("distincte.out");
const int NMAX = 1e5, BLOCK = 317, MOD = 666013;
int n, k, q, arr[NMAX], freq[NMAX], ans[NMAX], sum = 0;
struct Query
{
int st, dr, id;
bool operator < (const Query &other) const
{
int b1 = st / BLOCK, b2 = other.st / BLOCK;
if(b1 == b2)
return (b1 & 1 ? dr > other.dr : dr < other.dr);
return (b1 < b2);
}
};
Query queries[NMAX];
void adauga(int x)
{
if(freq[x] == 0)
sum += x;
freq[x]++;
if(sum >= MOD)
sum -= MOD;
}
void scoate(int x)
{
freq[x]--;
if(freq[x] == 0)
sum -= x;
if(sum < 0)
sum += MOD;
}
int main()
{
fin >> n >> k >> q;
for(int i = 0; i < n; i++)
fin >> arr[i];
for(int i = 0; i < q; i++)
{
fin >> queries[i].st >> queries[i].dr;
queries[i].st--;
queries[i].dr--;
queries[i].id = i;
}
sort(queries, queries + q);
int st = 0, dr = -1;
for(int i = 0; i < q; i++)
{
int qst = queries[i].st, qdr = queries[i].dr, id = queries[i].id;
while(st > qst)
adauga(arr[--st]);
while(st < qst)
scoate(arr[st++]);
while(dr < qdr)
adauga(arr[++dr]);
while(dr > qdr)
scoate(arr[dr--]);
ans[id] = sum;
}
for(int i = 0; i < q; i++)
fout << ans[i] << "\n";
fin.close();
fout.close();
return 0;
}