#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:167772160000")
using namespace std;
map<int, set<int> > positions;
vector<int> seg[410000];
int targ, el;
void push(int a, int beg, int end) {
  if (beg > targ || end < targ) return;
  seg[a].push_back(el);
  if (beg == end) return;
  push(a * 2, beg, (beg + end) / 2);
  push(a * 2 + 1, (beg + end) / 2 + 1, end);
}
void srt(int a, int beg, int end) {
  sort(seg[a].begin(), seg[a].end());
  if (beg == end) return;
  srt(a * 2, beg, (beg + end) / 2);
  srt(a * 2 + 1, (beg + end) / 2 + 1, end);
}
int targBeg, targEnd;
int getAmount(int a, int beg, int end) {
  if (beg > targEnd || end < targBeg) return 0;
  if (beg >= targBeg && end <= targEnd) {
    int low = 0;
    int high = seg[a].size();
    while (low < high) {
      int mid = (low + high) / 2;
      if (seg[a][mid] <= targEnd)
        low = mid + 1;
      else
        high = mid;
    }
    return low;
  }
  return getAmount(a * 2, beg, (beg + end) / 2) +
         getAmount(a * 2 + 1, (beg + end) / 2 + 1, end);
}
int a[110000];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < (n); i++) cin >> a[i];
  for (int i = n - 1; i >= 0; i--) {
    int x = a[i];
    positions[a[i]];
    map<int, set<int> >::iterator it = positions.find(a[i]);
    if (it->second.size() == k) {
      set<int>::iterator it2 = it->second.end();
      it2--;
      targ = i;
      el = *it2;
      push(1, 0, n - 1);
      it->second.erase(it2);
    }
    it->second.insert(i);
  }
  srt(1, 0, n - 1);
  int last = 0;
  int q;
  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);
    targBeg = l - 1;
    targEnd = r - 1;
    last = targEnd - targBeg + 1 - getAmount(1, 0, n - 1);
    cout << last << endl;
  }
  return 0;
}
