#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
const int M = 20;
int n, k, a[N], R[N];
pair<int, int> p[N];
int tot, rt[N], sum[N * M], ls[N * M], rs[N * M];
void ins(int &t, int e, int l, int r, int P) {
  t = ++tot;
  ls[t] = rs[t] = sum[t] = 0;
  if (l >= r) {
    sum[t] = sum[e] + 1;
    return;
  }
  int z = (l + r) >> 1;
  if (P <= z) {
    rs[t] = rs[e];
    ins(ls[t], ls[e], l, z, P);
  } else {
    ls[t] = ls[e];
    ins(rs[t], rs[e], z + 1, r, P);
  }
  sum[t] = sum[ls[t]] + sum[rs[t]];
}
int qry(int t, int l, int r, int L, int R) {
  if (!t) return 0;
  if (L <= l && r <= R) return sum[t];
  int z = (l + r) >> 1, ret = 0;
  if (L <= z) ret += qry(ls[t], l, z, L, R);
  if (R > z) ret += qry(rs[t], z + 1, r, L, R);
  return ret;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = (1); i < (n + 1); ++i) {
    scanf("%d", a + i);
    p[i] = make_pair(a[i], i);
    R[i] = 0;
  }
  sort(p + 1, p + 1 + n);
  for (int i = 1, j; i <= n; i = j) {
    j = i + 1;
    while (j <= n && p[i].first == p[j].first) ++j;
    for (int r = (i + k); r < (j); ++r) R[p[r].second] = p[r - k].second;
  }
  for (int i = (1); i < (n + 1); ++i) ins(rt[i], rt[i - 1], 0, n, R[i]);
  int q, last = 0;
  scanf("%d", &q);
  for (int _q = (0); _q < (q); ++_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);
    last = (r - l + 1) - qry(rt[r], 0, n, l, r);
    printf("%d\n", last);
  }
  return 0;
}
