#include <bits/stdc++.h>
using namespace std;
struct debugger {
  template <typename T>
  debugger &operator,(const T &v) {
    cerr << v << " ";
    return *this;
  }
} dbg;
inline long long gcd(long long a, long long b) {
  a = ((a) < 0 ? -(a) : (a));
  b = ((b) < 0 ? -(b) : (b));
  while (b) {
    a = a % b;
    swap(a, b);
  }
  return a;
}
long long ext_gcd(long long A, long long B, long long *X, long long *Y) {
  long long x2, y2, x1, y1, x, y, r2, r1, q, r;
  x2 = 1;
  y2 = 0;
  x1 = 0;
  y1 = 1;
  for (r2 = A, r1 = B; r1 != 0;
       r2 = r1, r1 = r, x2 = x1, y2 = y1, x1 = x, y1 = y) {
    q = r2 / r1;
    r = r2 % r1;
    x = x2 - (q * x1);
    y = y2 - (q * y1);
  }
  *X = x2;
  *Y = y2;
  return r2;
}
inline long long modInv(long long a, long long m) {
  long long x, y;
  ext_gcd(a, m, &x, &y);
  x %= m;
  if (x < 0) x += m;
  return x;
}
inline long long power(long long a, long long p) {
  long long res = 1, x = a;
  while (p) {
    if (p & 1) res = (res * x);
    x = (x * x);
    p >>= 1;
  }
  return res;
}
inline long long bigmod(long long a, long long p, long long m) {
  long long res = 1 % m, x = a % m;
  while (p) {
    if (p & 1) res = (res * x) % m;
    x = (x * x) % m;
    p >>= 1;
  }
  return res;
}
inline int STRLEN(char *s) {
  int p = 0;
  while (s[p]) p++;
  return p;
}
int dir4[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
const long long inf = 2147383647;
const long long mod = 1e9 + 7;
const double pi = 2 * acos(0.0);
const double eps = 1e-9;
const int Size = 100005;
int N, K, Q;
vector<int> POS[Size];
int A[Size];
struct vert {
  vector<int> List;
};
vert T[Size * 4];
void bt(int c, int s, int e) {
  if (s == e) {
    T[c].List.push_back(A[s]);
    return;
  }
  int L = c * 2, R = c * 2 + 1, M = (s + e) / 2;
  bt(L, s, M);
  bt(R, M + 1, e);
  T[c].List.clear();
  T[c].List.resize(T[L].List.size() + T[R].List.size());
  merge((T[L].List).begin(), (T[L].List).end(), (T[R].List).begin(),
        (T[R].List).end(), T[c].List.begin());
}
int qt(int c, int s, int e, int u, int v, int val) {
  if (e < u || s > v) return 0;
  if (s >= u && e <= v) {
    int pos = lower_bound((T[c].List).begin(), (T[c].List).end(), val) -
              T[c].List.begin();
    return pos;
  }
  int L = c * 2, R = c * 2 + 1, M = (s + e) / 2;
  int v1 = qt(L, s, M, u, v, val);
  int v2 = qt(R, M + 1, e, u, v, val);
  return v1 + v2;
}
void process() {
  for (int num = 1; num < Size; num++) {
    for (int i = 0; i < POS[num].size(); i++) {
      int p = POS[num][i];
      int prv = -1;
      if (i - K >= 0) prv = POS[num][i - K];
      A[p] = prv;
    }
  }
  bt(1, 1, N);
}
int main() {
  scanf("%d %d", &N, &K);
  for (int i = 1; i <= N; i++) {
    int num;
    scanf("%d", &num);
    POS[num].push_back(i);
  }
  process();
  scanf("%d", &Q);
  int res = 0;
  for (int i = 0; i < Q; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    u = (u + res) % N + 1;
    v = (v + res) % N + 1;
    if (u > v) swap(u, v);
    res = qt(1, 1, N, u, v, u);
    printf("%d\n", res);
  }
}
