#include <bits/stdc++.h>
using namespace std;
int arr[200009], a[200009];
vector<int> tree[4 * 200009], v[200009];
inline vector<int> merge(vector<int> v1, vector<int> v2) {
  vector<int> z;
  int i = 0, j = 0;
  while ((i < v1.size()) && (j < v2.size())) {
    if (v1[i] <= v2[j]) {
      z.push_back(v1[i]);
      i++;
    } else {
      z.push_back(v2[j]);
      j++;
    }
  }
  while (i < v1.size()) {
    z.push_back(v1[i]);
    i++;
  }
  while (j < v2.size()) {
    z.push_back(v2[j]);
    j++;
  }
  return z;
}
inline void initialize(int nod, int st, int end) {
  if (st == end) {
    tree[nod].push_back(arr[st]);
  } else {
    int mid = (st + end) >> 1;
    initialize(nod << 1, st, mid);
    initialize((nod << 1) + 1, mid + 1, end);
    tree[nod] = merge(tree[nod << 1], tree[(nod << 1) + 1]);
  }
}
inline int query(int nod, int st, int end, int l, int r, int k) {
  if (l > end || r < st) {
    return 0;
  } else if (l <= st && end <= r) {
    vector<int>::iterator it =
        lower_bound(tree[nod].begin(), tree[nod].end(), k);
    int num = 0;
    if (it != tree[nod].end()) {
      int u = it - tree[nod].begin();
      num = tree[nod].size() - u;
    }
    return num;
  } else {
    int mid = (st + end) >> 1;
    return query(nod << 1, st, mid, l, r, k) +
           query((nod << 1) + 1, mid + 1, end, l, r, k);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    v[a[i]].push_back(i);
    if ((int)v[a[i]].size() <= k) {
      arr[i] = -1;
    } else {
      int p = v[a[i]].size();
      p--;
      arr[i] = v[a[i]][p - k];
    }
  }
  initialize(1, 1, n);
  int q;
  cin >> q;
  int last = 0;
  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    l = (l + last) % n;
    l++;
    r = (r + last) % n;
    r++;
    if (l > r) {
      swap(l, r);
    }
    int ans = r - l + 1;
    ans = ans - query(1, 1, n, l, r, l);
    cout << ans << "\n";
    last = ans;
  }
}
