#include <bits/stdc++.h>
int N, K, Q, RMQ[17][100002], *a = RMQ[0], LOG[100002], H[100002], T[100002],
                              M[10000000], S[10000000], ls[10000000],
                              rs[10000000], n;
inline int rmq(int l, int r) {
  int move = (l - 1) / N * N;
  l -= move;
  r -= move;
  if (r >= N + N)
    return H[N];
  else if (r >= N)
    return std::min(H[r - N], T[l]);
  else {
    int LG = LOG[r - l + 1];
    return std::min(RMQ[LG][l], RMQ[LG][r - (1 << LG) + 1]);
  }
}
inline void nnd(int &p, int l, int r) {
  p = ++n;
  M[p] = rmq(l, r);
  S[p] = 0;
}
void P(int p, int l, int r, int L, int R, int w) {
  if (L <= l && r <= R) {
    M[p] = w;
    S[p] = 1;
    return;
  }
  int m = (l + r) >> 1;
  if (!ls[p]) nnd(ls[p], l, m);
  if (!rs[p]) nnd(rs[p], m + 1, r);
  if (S[p]) {
    M[ls[p]] = M[rs[p]] = M[p];
    S[ls[p]] = S[rs[p]] = 1;
    S[p] = 0;
  }
  if (L <= m) P(ls[p], l, m, L, R, w);
  if (R > m) P(rs[p], m + 1, r, L, R, w);
  M[p] = std::min(M[ls[p]], M[rs[p]]);
}
int G(int p, int l, int r, int L, int R) {
  if (!p) return rmq(std::max(l, L), std::min(r, R));
  if (S[p]) return M[p];
  if (L <= l && r <= R) return M[p];
  int m = (l + r) >> 1;
  if (R <= m) return G(ls[p], l, m, L, R);
  if (L > m) return G(rs[p], m + 1, r, L, R);
  return std::min(G(ls[p], l, m, L, R), G(rs[p], m + 1, r, L, R));
}
int main() {
  scanf("%d%d", &N, &K);
  for (int i = 1; i <= N; i++) scanf("%d", a + i);
  for (int i = 2; i <= N; i++) LOG[i] = LOG[i >> 1] + 1;
  for (int i = 1, k = 1; k + k <= N; i++, k <<= 1)
    for (int j = 1; j <= N - k - k + 1; j++)
      RMQ[i][j] = std::min(RMQ[i - 1][j], RMQ[i - 1][j + k]);
  H[0] = T[N + 1] = 2147483647;
  for (int i = 1; i <= N; i++) H[i] = std::min(H[i - 1], a[i]);
  for (int i = N; i; i--) T[i] = std::min(T[i + 1], a[i]);
  M[n = 1] = H[N];
  S[1] = 0;
  for (scanf("%d", &Q); Q--;) {
    int op, l, r, w;
    scanf("%d%d%d", &op, &l, &r);
    if (op == 1) {
      scanf("%d", &w);
      P(1, 1, N * K, l, r, w);
    } else
      printf("%d\n", G(1, 1, N * K, l, r));
  }
  return 0;
}

### Prompt

Please create a solution in Cpp to the following problem:

You are given an array a consisting of positive integers and q queries to this array. There are two types of queries: 

  * 1 l r x — for each index i such that l ≤ i ≤ r set ai = x. 
  * 2 l r — find the minimum among such ai that l ≤ i ≤ r. 



We decided that this problem is too easy. So the array a is given in a compressed form: there is an array b consisting of n elements and a number k in the input, and before all queries a is equal to the concatenation of k arrays b (so the size of a is n·k).

Input

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

The second line contains n integers — elements of the array b (1 ≤ bi ≤ 109).

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

Then q lines follow, each representing a query. Each query is given either as 1 l r x — set all elements in the segment from l till r (including borders) to x (1 ≤ l ≤ r ≤ n·k, 1 ≤ x ≤ 109) or as 2 l r — find the minimum among all elements in the segment from l till r (1 ≤ l ≤ r ≤ n·k).

Output

For each query of type 2 print the answer to this query — the minimum on the corresponding segment.

Examples

Input

3 1
1 2 3
3
2 1 3
1 1 2 4
2 1 3


Output

1
3


Input

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


Output

1
5
1

### Response

```cpp
#include <bits/stdc++.h>
int N, K, Q, RMQ[17][100002], *a = RMQ[0], LOG[100002], H[100002], T[100002],
                              M[10000000], S[10000000], ls[10000000],
                              rs[10000000], n;
inline int rmq(int l, int r) {
  int move = (l - 1) / N * N;
  l -= move;
  r -= move;
  if (r >= N + N)
    return H[N];
  else if (r >= N)
    return std::min(H[r - N], T[l]);
  else {
    int LG = LOG[r - l + 1];
    return std::min(RMQ[LG][l], RMQ[LG][r - (1 << LG) + 1]);
  }
}
inline void nnd(int &p, int l, int r) {
  p = ++n;
  M[p] = rmq(l, r);
  S[p] = 0;
}
void P(int p, int l, int r, int L, int R, int w) {
  if (L <= l && r <= R) {
    M[p] = w;
    S[p] = 1;
    return;
  }
  int m = (l + r) >> 1;
  if (!ls[p]) nnd(ls[p], l, m);
  if (!rs[p]) nnd(rs[p], m + 1, r);
  if (S[p]) {
    M[ls[p]] = M[rs[p]] = M[p];
    S[ls[p]] = S[rs[p]] = 1;
    S[p] = 0;
  }
  if (L <= m) P(ls[p], l, m, L, R, w);
  if (R > m) P(rs[p], m + 1, r, L, R, w);
  M[p] = std::min(M[ls[p]], M[rs[p]]);
}
int G(int p, int l, int r, int L, int R) {
  if (!p) return rmq(std::max(l, L), std::min(r, R));
  if (S[p]) return M[p];
  if (L <= l && r <= R) return M[p];
  int m = (l + r) >> 1;
  if (R <= m) return G(ls[p], l, m, L, R);
  if (L > m) return G(rs[p], m + 1, r, L, R);
  return std::min(G(ls[p], l, m, L, R), G(rs[p], m + 1, r, L, R));
}
int main() {
  scanf("%d%d", &N, &K);
  for (int i = 1; i <= N; i++) scanf("%d", a + i);
  for (int i = 2; i <= N; i++) LOG[i] = LOG[i >> 1] + 1;
  for (int i = 1, k = 1; k + k <= N; i++, k <<= 1)
    for (int j = 1; j <= N - k - k + 1; j++)
      RMQ[i][j] = std::min(RMQ[i - 1][j], RMQ[i - 1][j + k]);
  H[0] = T[N + 1] = 2147483647;
  for (int i = 1; i <= N; i++) H[i] = std::min(H[i - 1], a[i]);
  for (int i = N; i; i--) T[i] = std::min(T[i + 1], a[i]);
  M[n = 1] = H[N];
  S[1] = 0;
  for (scanf("%d", &Q); Q--;) {
    int op, l, r, w;
    scanf("%d%d%d", &op, &l, &r);
    if (op == 1) {
      scanf("%d", &w);
      P(1, 1, N * K, l, r, w);
    } else
      printf("%d\n", G(1, 1, N * K, l, r));
  }
  return 0;
}

```