#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <iostream>
#include <math.h>
using namespace std;
int n, m, k, bbclock, a[1000001], cnt = 0, ans1 = 0;
struct node
{
int l, r, id;
} b[1000001];
int c[1000001], ans[1000001];
bool cmp(struct node a, struct node b)
{
if ((a.l / bbclock) == (b.l / bbclock))
{
return a.r > b.r;
}
else
{
return (a.l / bbclock) < (b.l / bbclock);
}
}
int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("in.txt", "r", stdin);
#endif
int i, j, l, r, q = 0, L, R;
scanf("%d %d %d", &n, &m, &k);
bbclock = sqrt(n);
L = 1, R = n;
for (i = 1; i < n + 1; i++)
{
scanf("%d", &a[i]);
c[a[i]]++;
}
ans1=0;
for(i=1;i<k+1;i++)
{
ans1+=c[i]*c[i];
}
for (i = 1; i < m + 1; i++)
{
scanf("%d %d", &b[cnt].l, &b[cnt].r);
b[cnt].id = i;
cnt++;
}
sort(b, b + cnt, cmp);
for (i = 0; i < cnt; i++)
{
while (L < b[i].l)
{
ans1 = ans1 - 2 * c[a[L]] + 1;
c[a[L]]--;
L++;
}
while (L > b[i].l)
{
L--;
ans1 += 2 * c[a[L]] + 1;
c[a[L]]++;
}
while (R <b[i].r)
{
R++;
ans1 += 2 * c[a[R]] + 1;
c[a[R]]++;
}
while (R > b[i].r)
{
ans1 = ans1 - 2 * c[a[R]] + 1;
c[a[R]]--;
R--;
}
ans[b[i].id] = ans1;
}
for (i = 1; i < m+1; i++)
{
printf("%d\n", ans[i]);
}
return 0;
}