#include <bits/stdc++.h>
using namespace std;
const int N = 100005, LG = 20, INF = 1E9 + 7;
int n, q, k, t, l, r, v, mi = INF, a[N], rmq[N][LG];
int find_ans(int l, int r);
class CTree {
 public:
  int val, lz;
  CTree *lc, *rc;
  CTree(int _val, int _lz) {
    val = _val;
    lz = _lz;
    lc = rc = nullptr;
  }
  void down(int l, int r) {
    if (lc == nullptr) lc = new CTree(0, -1);
    if (rc == nullptr) rc = new CTree(0, -1);
    if (lz == -1) return;
    if (lz == 0) {
      lc->lz = rc->lz = 0;
      lc->val = find_ans(l, (l + r) / 2);
      rc->val = find_ans((l + r) / 2 + 1, r);
    } else {
      lc->lz = lc->val = lz;
      rc->lz = rc->val = lz;
    }
    lz = -1;
  }
  void upd(int l, int r, int L, int R, int v) {
    if (l > R || r < L) return;
    if (L <= l && r <= R) {
      val = lz = v;
      return;
    }
    down(l, r);
    lc->upd(l, (l + r) / 2, L, R, v);
    rc->upd((l + r) / 2 + 1, r, L, R, v);
    val = min(lc->val, rc->val);
  }
  int que(int l, int r, int L, int R) {
    if (l > R || r < L) return INF;
    if (L <= l && r <= R) return val;
    down(l, r);
    return min(lc->que(l, (l + r) / 2, L, R),
               rc->que((l + r) / 2 + 1, r, L, R));
  }
} * rt;
int find_min(int l, int r) {
  int lg = 31 - __builtin_clz(r - l + 1);
  return min(rmq[l][lg], rmq[r - (1 << lg) + 1][lg]);
}
int find_ans(int l, int r) {
  if (r - l + 1 >= n) {
    l = 1;
    r = n;
  } else {
    l = (l - 1) % n + 1;
    r = (r - 1) % n + 1;
  }
  if (l <= r)
    return find_min(l, r);
  else
    return min(find_min(l, n), find_min(1, r));
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    mi = min(mi, rmq[i][0] = a[i]);
  }
  for (int j = 1; (1 << j) <= n; j++)
    for (int i = 1; i + (1 << j) - 1 <= n; i++)
      rmq[i][j] = min(rmq[i][j - 1], rmq[i + (1 << (j - 1))][j - 1]);
  rt = new CTree(find_ans(1, n), 0);
  scanf("%d", &q);
  while (q--) {
    scanf("%d%d%d", &t, &l, &r);
    if (t == 1) {
      scanf("%d", &v);
      rt->upd(1, n * k, l, r, v);
    } else
      printf("%d\n", rt->que(1, n * k, l, r));
  }
}

### Prompt

Please formulate a Cpp solution 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>
using namespace std;
const int N = 100005, LG = 20, INF = 1E9 + 7;
int n, q, k, t, l, r, v, mi = INF, a[N], rmq[N][LG];
int find_ans(int l, int r);
class CTree {
 public:
  int val, lz;
  CTree *lc, *rc;
  CTree(int _val, int _lz) {
    val = _val;
    lz = _lz;
    lc = rc = nullptr;
  }
  void down(int l, int r) {
    if (lc == nullptr) lc = new CTree(0, -1);
    if (rc == nullptr) rc = new CTree(0, -1);
    if (lz == -1) return;
    if (lz == 0) {
      lc->lz = rc->lz = 0;
      lc->val = find_ans(l, (l + r) / 2);
      rc->val = find_ans((l + r) / 2 + 1, r);
    } else {
      lc->lz = lc->val = lz;
      rc->lz = rc->val = lz;
    }
    lz = -1;
  }
  void upd(int l, int r, int L, int R, int v) {
    if (l > R || r < L) return;
    if (L <= l && r <= R) {
      val = lz = v;
      return;
    }
    down(l, r);
    lc->upd(l, (l + r) / 2, L, R, v);
    rc->upd((l + r) / 2 + 1, r, L, R, v);
    val = min(lc->val, rc->val);
  }
  int que(int l, int r, int L, int R) {
    if (l > R || r < L) return INF;
    if (L <= l && r <= R) return val;
    down(l, r);
    return min(lc->que(l, (l + r) / 2, L, R),
               rc->que((l + r) / 2 + 1, r, L, R));
  }
} * rt;
int find_min(int l, int r) {
  int lg = 31 - __builtin_clz(r - l + 1);
  return min(rmq[l][lg], rmq[r - (1 << lg) + 1][lg]);
}
int find_ans(int l, int r) {
  if (r - l + 1 >= n) {
    l = 1;
    r = n;
  } else {
    l = (l - 1) % n + 1;
    r = (r - 1) % n + 1;
  }
  if (l <= r)
    return find_min(l, r);
  else
    return min(find_min(l, n), find_min(1, r));
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    mi = min(mi, rmq[i][0] = a[i]);
  }
  for (int j = 1; (1 << j) <= n; j++)
    for (int i = 1; i + (1 << j) - 1 <= n; i++)
      rmq[i][j] = min(rmq[i][j - 1], rmq[i + (1 << (j - 1))][j - 1]);
  rt = new CTree(find_ans(1, n), 0);
  scanf("%d", &q);
  while (q--) {
    scanf("%d%d%d", &t, &l, &r);
    if (t == 1) {
      scanf("%d", &v);
      rt->upd(1, n * k, l, r, v);
    } else
      printf("%d\n", rt->que(1, n * k, l, r));
  }
}

```