#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int lgN = 24;
int tree[N * lgN], ls[N * lgN], rs[N * lgN];
int rt[N * lgN], alloc;
queue<int> q[N];
void build(int &rt, int l, int r) {
  rt = ++alloc;
  ls[rt] = l, rs[rt] = r;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(ls[rt], l, mid);
  build(rs[rt], mid + 1, r);
}
void update(int &rt, int pre, int l, int r, int pos, int v) {
  rt = ++alloc;
  ls[rt] = ls[pre], rs[rt] = rs[pre];
  tree[rt] = tree[pre] + v;
  if (l == r) return;
  int mid = (l + r) >> 1;
  if (pos <= mid)
    update(ls[rt], ls[pre], l, mid, pos, v);
  else
    update(rs[rt], rs[pre], mid + 1, r, pos, v);
}
int query(int rtl, int rtr, int l, int r, int ql, int qr) {
  if (ql <= l && qr >= r) {
    return tree[rtr] - tree[rtl];
  }
  int res = 0;
  int mid = (l + r) >> 1;
  if (ql <= mid) res += query(ls[rtl], ls[rtr], l, mid, ql, qr);
  if (qr > mid) res += query(rs[rtl], rs[rtr], mid + 1, r, ql, qr);
  return res;
}
int main(int argc, const char *argv[]) {
  int n, k;
  scanf("%d %d", &n, &k);
  build(rt[0], 1, n);
  for (int x, i = 1; i <= n; ++i) {
    scanf("%d", &x);
    q[x].push(i);
    update(rt[i], rt[i - 1], 1, n, i, 1);
    if (q[x].size() > k) {
      int tmp = q[x].front();
      q[x].pop();
      update(rt[i], rt[i], 1, n, tmp, -1);
    }
  }
  int q, last = 0;
  scanf("%d", &q);
  while (q--) {
    int l, r;
    scanf("%d %d", &l, &r);
    l = (l + last) % n + 1;
    r = (r + last) % n + 1;
    if (l > r) swap(l, r);
    printf("%d\n", last = query(rt[l - 1], rt[r], 1, n, l, r));
  }
  return 0;
}
