#include<bits/stdc++.h> #define MAX_N 100000 usingnamespace std; constint MAGIC = 316; template <classT> inlinevoidread(T &x){ x = 0; int c = getchar(), f = 1; for (; !isdigit(c); c = getchar()) if (c == 45) f = -1; for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-'0'); } int n, c, m, a[MAX_N+5], buk[MAX_N+5]; int num[MAGIC+5][MAX_N+5], cnt[MAGIC+5][MAGIC+5]; intblock(int p){return p/MAGIC+1;} intL(int num){returnmax((num-1)*MAGIC, 1);} intR(int num){returnmin(num*MAGIC-1, n);} intmain(){ read(n), read(c), read(m); for (int i = 1; i <= n; i++) read(a[i]), num[block(i)][a[i]]++; for (int i = 2; i <= block(n); i++) for (int j = 1; j <= c; j++) num[i][j] += num[i-1][j]; for (int i = 1, t; i <= block(n); i++) { memset(buk, 0, sizeof buk), t = 0; for (int j = i; j <= block(n); cnt[i][j++] = t) for (int p = L(j); p <= R(j); buk[a[p++]]++) if (buk[a[p]]&1) t++; elseif (buk[a[p]]) t--; } memset(buk, 0, sizeof buk); for (int l, r, ans = 0; m; m--) { read(l), read(r); l = (l+ans)%n+1, r = (r+ans)%n+1; if (l > r) swap(l, r); ans = 0; if (block(r)-block(l) <= 1) { for (int i = l; i <= r; buk[a[i++]]++) if (buk[a[i]]&1) ans++; elseif (buk[a[i]]) ans--; for (int i = l; i <= r; i++) buk[a[i]]--; } else { ans = cnt[block(l)+1][block(r)-1]; for (int i = l; i <= R(block(l)); i++) buk[a[i]]++; for (int i = r; i >= L(block(r)); i--) buk[a[i]]++; for (int i = l; i <= R(block(l)); buk[a[i++]] = 0) if (buk[a[i]]) { int t = num[block(r)-1][a[i]]-num[block(l)][a[i]]; if (!t) ans += ((buk[a[i]]&1) == 0); elseif ((t&1) && (buk[a[i]]&1)) ans++; elseif (!(t&1) && (buk[a[i]]&1)) ans--; } for (int i = r; i >= L(block(r)); buk[a[i--]] = 0) if (buk[a[i]]) { int t = num[block(r)-1][a[i]]-num[block(l)][a[i]]; if (!t) ans += ((buk[a[i]]&1) == 0); elseif ((t&1) && (buk[a[i]]&1)) ans++; elseif (!(t&1) && (buk[a[i]]&1)) ans--; } } printf("%d\n", ans); } return0; }