#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int N = 100100;
const int M = N * 20;
int cnt[M], ls[M], rs[M], tot = 0;
int build(int l, int r) {
  int x = tot++;
  cnt[x] = 0;
  if (l != r) {
    int m = l + r >> 1;
    ls[x] = build(l, m);
    rs[x] = build(m + 1, r);
  }
  return x;
}
int add(int o, int p, int l, int r) {
  int x = tot++;
  cnt[x] = cnt[o];
  if (l == r) {
    cnt[x]++;
    return x;
  }
  int m = l + r >> 1;
  if (p <= m) {
    ls[x] = add(ls[o], p, l, m);
    rs[x] = rs[o];
  } else {
    ls[x] = ls[o];
    rs[x] = add(rs[o], p, m + 1, r);
  }
  cnt[x] = cnt[ls[x]] + cnt[rs[x]];
  return x;
}
int query(int o, int p, int l, int r) {
  if (l == p) return cnt[o];
  int md = l + r >> 1;
  if (p <= md)
    return query(ls[o], p, l, md) + cnt[rs[o]];
  else
    return query(rs[o], p, md + 1, r);
}
int a[N], p[N], nxt[N], now[N], num[N], tr[N];
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  build(1, n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    if (!now[a[i]]) now[a[i]] = i;
    nxt[p[a[i]]] = i;
    p[a[i]] = i;
    if (num[a[i]]++ > k) now[a[i]] = nxt[now[a[i]]];
    tr[i] = num[a[i]] > k ? add(tr[i - 1], now[a[i]], 1, n) : tr[i - 1];
  }
  int q, ans = 0;
  scanf("%d", &q);
  while (q--) {
    int x, y;
    scanf("%d %d", &x, &y);
    x = (x + ans) % n + 1;
    y = (y + ans) % n + 1;
    if (x > y) swap(x, y);
    ans = y - x + 1 - query(tr[y], x, 1, n);
    cout << ans << endl;
  }
}
