1 #include<cstdio>
2 #include<cstdlib>
3 #include<cmath>
4 #include<cstring>
5 #include<algorithm>
6 #include<iostream>
7 #include<vector>
8 #include<map>
9 #include<set>
10 #include<queue>
11 #include<string>
12 #define inf 1000000000
13 #define maxn 100000+1000
14 #define maxm 2000
15 #define eps 1e-10
16 #define pa pair<int,int>
17 #define for0(i,n) for(int i=0;i<=n;i++)
18 #define for1(i,n) for(int i=1;i<=n;i++)
19 #define for2(i,x,y) for(int i=x;i<=y;i++)
20 using namespace std;
21 inline int read()
22 {
23 int x=0,f=1;char ch=getchar();
24 while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
25 while(ch>=‘0‘&&ch<=‘9‘){x=10*x+ch-‘0‘;ch=getchar();}
26 return x*f;
27 }
28 struct rec{int x,id;}b[maxn];
29 int n,m,c,ans,block,a[maxn],l[maxn],r[maxn],pos[maxn],f[maxm][maxm],sum[maxn];
30 bool mark[maxn];
31 inline bool cmp(rec a,rec b)
32 {
33 return a.x<b.x||(a.x==b.x&&a.id<b.id);
34 }
35 inline int findup(int val,int pos)
36 {
37 int ll=l[val],rr=r[val],mid;
38 while(ll<=rr)
39 {
40 mid=(ll+rr)>>1;
41 if(b[mid].id>pos)rr=mid-1;else ll=mid+1;
42 }
43 return rr;
44 }
45 inline int finddown(int val,int pos)
46 {
47 int ll=l[val],rr=r[val],mid;
48 while(ll<=rr)
49 {
50 mid=(ll+rr)>>1;
51 if(b[mid].id>=pos)rr=mid-1;else ll=mid+1;
52 }
53 return ll;
54 }
55 inline int find(int val,int x,int y)
56 {
57 return findup(val,y)-finddown(val,x)+1;
58 }
59 void ask(int x,int y)
60 {
61 x=(x+ans)%n+1;y=(y+ans)%n+1;if(x>y)swap(x,y);
62 ans=0;
63 int bx=pos[x],by=pos[y],r=bx*block,l=(by-1)*block+1,t1,t2;
64 if(by-bx<=1)
65 {
66 for2(i,x,y)
67 {
68 sum[a[i]]++;
69 if(sum[a[i]]&1&&sum[a[i]]!=1)ans--;
70 if(!(sum[a[i]]&1))ans++;
71 }
72 for2(i,x,y)sum[a[i]]=0;
73 }
74 else
75 {
76 ans=f[bx+1][by-1];
77 for2(i,x,r)if(!mark[a[i]])
78 {
79 mark[a[i]]=1;
80 t1=find(a[i],x,y);t2=find(a[i],r+1,l-1);
81 if(t1&1&&!(t2&1)&&t2)ans--;
82 if(!(t1&1)&&(t2&1||!t2))ans++;
83 }
84 for2(i,l,y)if(!mark[a[i]])
85 {
86 mark[a[i]]=1;
87 t1=find(a[i],x,y);t2=find(a[i],r+1,l-1);
88 if(t1&1&&!(t2&1)&&t2)ans--;
89 if(!(t1&1)&&(t2&1||!t2))ans++;
90 }
91 for2(i,x,r)mark[a[i]]=0;
92 for2(i,l,y)mark[a[i]]=0;
93 }
94 printf("%d\n",ans);
95 }
96 int main()
97 {
98 freopen("input.txt","r",stdin);
99 freopen("output.txt","w",stdout);
100 n=read();c=read();m=read();
101 block=sqrt((double)n/log((double)n)*log(2));
102 for1(i,n)
103 {
104 a[i]=read();b[i].x=a[i];b[i].id=i;
105 pos[i]=(i-1)/block+1;
106 }
107 sort(b+1,b+n+1,cmp);
108 for1(i,n+1)
109 if(b[i].x!=b[i-1].x)
110 {
111 r[b[i-1].x]=i-1;l[b[i].x]=i;
112 }
113 for1(i,pos[n])
114 {
115 ans=0;memset(sum,0,sizeof(sum));
116 for2(j,(i-1)*block+1,n)
117 {
118 sum[a[j]]++;
119 if(sum[a[j]]&1&&sum[a[j]]!=1)ans--;
120 if(!(sum[a[j]]&1))ans++;
121 f[i][pos[j]]=ans;
122 }
123 }
124 memset(sum,0,sizeof(sum));
125 ans=0;
126 while(m--)ask(read(),read());
127 return 0;
128 }