#include <bits/stdc++.h>
using namespace std;
const int MX = 1e5 + 10;
int A[MX];
vector<int> pos[MX];
vector<int> st[MX << 2];
void build(int l, int r, int nodo) {
  if (l == r) {
    st[nodo] = vector<int>(1, A[l]);
    return;
  }
  int med = (l + r) / 2;
  build(l, med, nodo * 2);
  build(med + 1, r, nodo * 2 + 1);
  merge(st[nodo * 2].begin(), st[nodo * 2].end(), st[nodo * 2 + 1].begin(),
        st[nodo * 2 + 1].end(), back_inserter(st[nodo]));
  return;
}
int query(int ini, int fin, int val, int l, int r, int nodo) {
  if (fin < l || r < ini) return 0;
  if (ini <= l && r <= fin) {
    int pos =
        lower_bound(st[nodo].begin(), st[nodo].end(), val) - st[nodo].begin();
    return pos;
  }
  int med = (l + r) / 2;
  int L = query(ini, fin, val, l, med, nodo * 2);
  int R = query(ini, fin, val, med + 1, r, nodo * 2 + 1);
  return L + R;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout.precision(10);
  cout << fixed;
  int n, q, x, y, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> x;
    int sz = pos[x].size();
    if (sz < k) {
      A[i] = -1;
    } else {
      A[i] = pos[x][sz - k];
    }
    pos[x].push_back(i);
  }
  build(0, n - 1, 1);
  int l, r, last;
  last = 0;
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> x >> y;
    x = ((x + last) % n) + 1;
    y = ((y + last) % n) + 1;
    if (x > y) swap(x, y);
    last = query(x - 1, y - 1, x - 1, 0, n - 1, 1);
    cout << last << "\n";
    ;
  }
  return 0;
}
