As you might remember from our previous rounds, Vova really likes computer games. Now he is playing a strategy game known as Rage of Empires.

In the game Vova can hire n different warriors; ith warrior has the type ai. Vova wants to create a balanced army hiring some subset of warriors. An army is called balanced if for each type of warrior present in the game there are not more than k warriors of this type in the army. Of course, Vova wants his army to be as large as possible.

To make things more complicated, Vova has to consider q different plans of creating his army. ith plan allows him to hire only warriors whose numbers are not less than li and not greater than ri.

Help Vova to determine the largest size of a balanced army for each plan.

Be aware that the plans are given in a modified way. See input section for details.

Input

The first line contains two integers n and k (1 ≤ n, k ≤ 100000).

The second line contains n integers a1, a2, ... an (1 ≤ ai ≤ 100000).

The third line contains one integer q (1 ≤ q ≤ 100000).

Then q lines follow. ith line contains two numbers xi and yi which represent ith plan (1 ≤ xi, yi ≤ n).

You have to keep track of the answer to the last plan (let's call it last). In the beginning last = 0. Then to restore values of li and ri for the ith plan, you have to do the following:

  1. li = ((xi + last) mod n) + 1; 
  2. ri = ((yi + last) mod n) + 1; 
  3. If li > ri, swap li and ri. 

Output

Print q numbers. ith number must be equal to the maximum size of a balanced army when considering ith plan.

Example

Input

6 2
1 1 1 2 2 2
5
1 6
4 3
1 1
2 6
2 6


Output

2
4
1
3
2

Note

In the first example the real plans are: 

  1. 1 2
  2. 1 6
  3. 6 6
  4. 2 4
  5. 4 6
#include <bits/stdc++.h>
using namespace std;
int N, K, NR = 1, a[100100], g[100100], root[100100], Q, lst;
vector<int> c[100100];
struct range {
  int l, r, sum;
} r[4400400];
int u(int i, int rs, int re, int p, int d) {
  int n = ++NR;
  r[n] = r[i];
  if (rs == re - 1)
    r[n].sum += d;
  else {
    int m = (rs + re) / 2;
    if (p < m)
      r[n].l = u(r[n].l, rs, m, p, d);
    else
      r[n].r = u(r[n].r, m, re, p, d);
    r[n].sum = r[r[n].l].sum + r[r[n].r].sum;
  }
  return n;
}
int q(int i, int rs, int re, int qs, int qe) {
  if (rs == qs && re == qe) return r[i].sum;
  int m = (rs + re) / 2, n = 0;
  if (qs < m && r[i].l) n += q(r[i].l, rs, m, qs, min(m, qe));
  if (qe > m && r[i].r) n += q(r[i].r, m, re, max(qs, m), qe);
  return n;
}
int main() {
  scanf("%d %d", &N, &K);
  for (int i = (1); i < (N + 1); i++) {
    scanf("%d", &a[i]);
    c[a[i]].push_back(i);
  }
  for (int i = (1); i < (100100); i++) {
    for (int j = 0; j + K < ((int)c[i].size()); j++) {
      g[c[i][j]] = c[i][j + K];
    }
  }
  root[N + 1] = 1;
  for (int i = N; i >= 1; i--) {
    root[i] = u(root[i + 1], 1, N + 1, i, 1);
    if (g[i]) root[i] = u(root[i], 1, N + 1, g[i], -1);
  }
  scanf("%d", &Q);
  for (int z = (0); z < (Q); z++) {
    int x, y;
    scanf("%d %d", &x, &y);
    x = (x + lst) % N + 1, y = (y + lst) % N + 1;
    if (x > y) swap(x, y);
    lst = q(root[x], 1, N + 1, x, y + 1);
    printf("%d\n", lst);
  }
  return 0;
}
