#include <bits/stdc++.h>
using namespace std;
template <typename _T>
inline void _DBG(const char *s, _T x) {
  cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a) {
  while (*s != ',') cerr << *s++;
  cerr << " = " << x << ',';
  _DBG(s + 1, a...);
}
template <typename TP>
struct pSegmentTree {
  long long MAX;
  TP init;
  struct node {
    TP val;
    node *left = nullptr, *right = nullptr;
    long long l, r;
    node(long long L, long long R, TP v) : val(v), l(L), r(R) {}
  };
  vector<node *> roots;
  pSegmentTree(long long n, TP zero) : init(zero) {
    MAX = 1LL << (64 - __builtin_clzll(n));
    roots.push_back(new node(0, MAX - 1, init));
  }
  void check(node *root) {
    long long m = (root->l + root->r) / 2;
    if (root->left == nullptr) root->left = new node(root->l, m, init);
    if (root->right == nullptr) root->right = new node(m + 1, root->r, init);
  }
  node *add(node *root, long long id, TP v) {
    node *res = new node(*root);
    res->val += v;
    if (res->l == res->r) return res;
    long long m = (res->l + res->r) / 2;
    check(res);
    if (id <= m)
      res->left = add(res->left, id, v);
    else
      res->right = add(res->right, id, v);
    return res;
  }
  TP ask(node *root, long long a, long long b) {
    if (root->r < a || b < root->l) return init;
    if (a <= root->l && root->r <= b) return root->val;
    check(root);
    return ask(root->left, a, b) + ask(root->right, a, b);
  }
  void update(long long id, TP v, int state = -1) {
    if (state == -1) state += (int)(roots).size();
    assert(state < (int)(roots).size());
    roots.push_back(add(roots[state], id, v));
  }
  TP query(long long a, long long b, int state = -1) {
    if (state == -1) state += (int)(roots).size();
    assert(state < (int)(roots).size());
    return ask(roots[state], a, b);
  }
};
const int N = 1e5 + 7;
int n, k, t[N], p[N];
vector<int> pos[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> t[i];
    pos[t[i]].push_back(i);
    if ((int)(pos[t[i]]).size() <= k)
      p[i] = 0;
    else
      p[i] = pos[t[i]][(int)(pos[t[i]]).size() - k - 1];
  }
  pSegmentTree<int> tree(n + 7, 0);
  for (int i = 1; i <= n; i++) tree.update(p[i], 1);
  int q, last = 0;
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    l = (l + last) % n + 1;
    r = (r + last) % n + 1;
    if (l > r) swap(l, r);
    last = tree.query(0, l - 1, r) - tree.query(0, l - 1, l - 1);
    cout << last << "\n";
  }
  return 0;
}
