#include <bits/stdc++.h>
using namespace std;
struct node {
  int l, r, sum;
} t[100000 * 20 + 10];
int n, k, m, cnt;
vector<int> v[100000 + 10];
int root[100000 + 10], a[100000 + 10], last[100000 + 10];
void build(int &x, int l, int r) {
  x = ++cnt;
  if (l == r) return;
  int mid = (l + r) / 2;
  build(t[x].l, l, mid);
  build(t[x].r, mid + 1, r);
}
void insert(int &x, int l, int r, int rk) {
  t[++cnt] = t[x];
  x = cnt;
  t[x].sum++;
  if (l == r) return;
  int mid = (l + r) / 2;
  if (mid >= rk)
    insert(t[x].l, l, mid, rk);
  else
    insert(t[x].r, mid + 1, r, rk);
}
int query(int i, int j, int l, int r, int x, int y) {
  if (l >= x && r <= y) return t[j].sum - t[i].sum;
  int mid = (l + r) / 2, sum = 0;
  if (mid >= x) sum += query(t[i].l, t[j].l, l, mid, x, y);
  if (mid < y) sum += query(t[i].r, t[j].r, mid + 1, r, x, y);
  return sum;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (v[a[i]].size() >= k) last[i] = v[a[i]][v[a[i]].size() - k];
    v[a[i]].push_back(i);
  }
  build(root[0], 0, n);
  for (int i = 1; i <= n; i++) {
    root[i] = root[i - 1];
    insert(root[i], 0, n, last[i]);
  }
  scanf("%d", &m);
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x = (x + ans) % n + 1;
    y = (y + ans) % n + 1;
    if (x > y) swap(x, y);
    printf("%d\n", ans = query(root[x - 1], root[y], 0, n, 0, x - 1));
  }
  return 0;
}
