#include <bits/stdc++.h>
using namespace std;
const int N = 100005, LIM = N * 100;
int tree[LIM], lc[LIM], rc[LIM];
vector<int> v[N];
int a[N], root[N], counter = 1, cur;
int get(int p) {
  int newp = counter++;
  lc[newp] = lc[p];
  rc[newp] = rc[p];
  return newp;
}
void combine(int p, int l, int r) { tree[p] = tree[l] + tree[r]; }
int modify(int p, int l, int r, int pos, int val) {
  int newp = get(p);
  if (l == r) {
    tree[newp] = val;
    return newp;
  }
  int mid = (l + r) >> 1;
  if (pos <= mid) {
    lc[newp] = modify(lc[p], l, mid, pos, val);
  } else {
    rc[newp] = modify(rc[p], mid + 1, r, pos, val);
  }
  combine(newp, lc[newp], rc[newp]);
  return newp;
}
int query(int p, int l, int r, int L, int R) {
  if (L <= l && r <= R) {
    return tree[p];
  }
  int mid = (l + r) >> 1;
  int ans = 0;
  if (L <= mid) {
    ans += query(lc[p], l, mid, L, min(R, mid));
  }
  if (R > mid) {
    ans += query(rc[p], mid + 1, r, max(L, mid + 1), R);
  }
  return ans;
}
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    v[a[i]].push_back(i);
    int sz = v[a[i]].size();
    if (sz > k) {
      int lf = v[a[i]][sz - k - 1];
      cur = modify(cur, 1, n, lf, 0);
    }
    root[i] = modify(cur, 1, n, i, 1);
    cur = root[i];
  }
  int q;
  scanf("%d", &q);
  int last = 0;
  while (q--) {
    int l, r;
    scanf("%d %d", &l, &r);
    l += last;
    r += last;
    l %= n;
    r %= n;
    l++;
    r++;
    if (l > r) swap(l, r);
    last = query(root[r], 1, n, l, r);
    printf("%d\n", last);
  }
  return 0;
}
