#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 9;
int a[maxn];
vector<int> v[maxn];
int b[maxn];
vector<int> tree[4 * maxn];
long long ans;
void BT(int node, int l, int r) {
  if (l == r) {
    tree[node].push_back(b[l]);
    return;
  }
  int mid = (l + r) >> 1;
  BT(node << 1, l, mid);
  BT(node << 1 | 1, mid + 1, r);
  for (int i = l; i <= r; i++) {
    tree[node].push_back(b[i]);
  }
  sort(tree[node].begin(), tree[node].end());
}
void Query(int node, int l, int r, int a, int b) {
  if (l == r) {
    int temp = lower_bound(tree[node].begin(), tree[node].end(), a) -
               (tree[node].begin());
    ans += temp;
    return;
  }
  if (a <= l && r <= b) {
    int temp = lower_bound(tree[node].begin(), tree[node].end(), a) -
               (tree[node].begin());
    ans += temp;
    return;
  }
  int mid = (l + r) >> 1;
  if (a > mid) {
    Query(node << 1 | 1, mid + 1, r, a, b);
  } else if (b <= mid) {
    Query(node << 1, l, mid, a, b);
  } else {
    Query(node << 1 | 1, mid + 1, r, a, b);
    Query(node << 1, l, mid, a, b);
  }
}
int main() {
  int n, k;
  while (scanf("%d%d", &n, &k) != EOF) {
    memset(b, -1, sizeof(b));
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      v[a[i]].push_back(i);
      if (v[a[i]].size() > k) {
        b[i] = v[a[i]][v[a[i]].size() - k - 1];
      }
    }
    BT(1, 1, n);
    int q;
    scanf("%d", &q);
    int last = 0;
    while (q--) {
      int x, y;
      scanf("%d%d", &x, &y);
      int l = (x + last) % n + 1;
      int r = (y + last) % n + 1;
      if (l > r) {
        swap(l, r);
      }
      ans = 0;
      Query(1, 1, n, l, r);
      printf("%d\n", ans);
      last = ans;
    }
  }
  return 0;
}
