#include <bits/stdc++.h>
using namespace std;
ifstream fin("distincte.in");
ofstream fout("distincte.out");
const int bloc = 316;
const int mod = 666013;
struct Query
{
int l, r, poz;
constexpr bool operator<(const Query& e) const
{
int block_a = l / bloc;
int block_b = e.l / bloc;
if(block_a != block_b) return block_a < block_b;
return (block_a & 1) ? (r < e.r) : (r > e.r);
}
} Q[100001];
int fr[100001];
int a[100001];
int sol[100001];
int n, k, m;
int suma;
void adauga(int x)
{
if(fr[a[x]] == 0) suma = (suma + a[x]) % mod;
fr[a[x]]++;
}
void sterge(int x)
{
fr[a[x]]--;
if(fr[a[x]] == 0)
{
suma -= a[x];
if(suma < 0) suma += mod;
}
}
void MOO()
{
int cur_l, cur_r, st, dr, i;
cur_l = 1;
cur_r = 0;
for(i=1; i<=m; i++)
{
st = Q[i].l;
dr = Q[i].r;
while(cur_l > st)
{
cur_l--;
adauga(cur_l);
}
while(cur_r < dr)
{
cur_r++;
adauga(cur_r);
}
while(cur_l < st)
{
sterge(cur_l);
cur_l++;
}
while(cur_r > dr)
{
sterge(cur_r);
cur_r--;
}
sol[Q[i].poz] = suma;
}
}
int main()
{
ios_base::sync_with_stdio(0);
fin.tie(0);
fout.tie(0);
int i;
fin >> n >> k >> m;
for(i = 1; i <= n; i++)
fin >> a[i];
for(i = 1; i <= m; i++)
{
fin >> Q[i].l >> Q[i].r;
Q[i].poz = i;
}
sort(Q + 1, Q + m + 1);
MOO();
for(i = 1; i <= m; i++)
fout << sol[i] << "\n";
fin.close();
fout.close();
return 0;
}