#include <bits/stdc++.h>
using namespace std;
const int Inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
int n, k, q, m;
int b[1 << 17];
int mode[1 << 17], l[1 << 17], r[1 << 17], x[1 << 17];
struct Segtree {
  int dt[8 << 17], wp[8 << 17];
  void inline pd(int now) {
    if (wp[now]) {
      dt[now << 1] = wp[now];
      dt[now << 1 | 1] = wp[now];
      wp[now << 1] = wp[now];
      wp[now << 1 | 1] = wp[now];
      wp[now] = 0;
    }
  }
  void inline pu(int now) { dt[now] = min(dt[now << 1], dt[now << 1 | 1]); }
  void add(int l, int r, int x, int now = 1, int nl = 0,
           int nr = (1 << 18) - 1) {
    if (nl >= l && nr <= r) return void((dt[now] = x, wp[now] = x));
    if (nl > r || nr < l) return;
    pd(now);
    int m = (nl + nr) >> 1;
    add(l, r, x, now << 1, nl, m);
    add(l, r, x, now << 1 | 1, m + 1, nr);
    pu(now);
  }
  int qry(int l, int r, int now = 1, int nl = 0, int nr = (1 << 18) - 1) {
    if (nl >= l && nr <= r) return dt[now];
    if (nl > r || nr < l) return Inf;
    pd(now);
    int m = (nl + nr) >> 1;
    return min(qry(l, r, now << 1, nl, m), qry(l, r, now << 1 | 1, m + 1, nr));
  }
} psg, seg;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= (n); i++) scanf("%d", b + i);
  scanf("%d", &q);
  vector<int> lss;
  for (int i = 1; i <= (q); i++) {
    scanf("%d", mode + i);
    if (mode[i] == 1)
      scanf("%d%d%d", l + i, r + i, x + i);
    else
      scanf("%d%d", l + i, r + i);
    lss.push_back(l[i]);
    lss.push_back(r[i] + 1);
  }
  lss.push_back(1);
  lss.push_back(n * k + 1);
  for (int i = 0; i < (n); i++) psg.add(i, i, b[i + 1]);
  sort((lss).begin(), (lss).end());
  lss.resize(unique((lss).begin(), (lss).end()) - lss.begin());
  m = lss.size() - 1;
  for (int i = 0; i < (m); i++) {
    int now = lss[i] - 1, nxt = lss[i + 1] - 2;
    if (nxt - now + 1 >= n)
      seg.add(i, i, psg.qry(0, n - 1));
    else if (now % n <= nxt % n)
      seg.add(i, i, psg.qry(now % n, nxt % n));
    else
      seg.add(i, i, min(psg.qry(now % n, n - 1), psg.qry(0, nxt % n)));
  }
  for (int i = 1; i <= (q); i++) {
    l[i] = lower_bound((lss).begin(), (lss).end(), l[i]) - lss.begin();
    r[i] = upper_bound((lss).begin(), (lss).end(), r[i]) - lss.begin() - 1;
    if (mode[i] == 1)
      seg.add(l[i], r[i], x[i]);
    else
      printf("%d\n", seg.qry(l[i], r[i]));
  }
  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>
using namespace std;
const int Inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
int n, k, q, m;
int b[1 << 17];
int mode[1 << 17], l[1 << 17], r[1 << 17], x[1 << 17];
struct Segtree {
  int dt[8 << 17], wp[8 << 17];
  void inline pd(int now) {
    if (wp[now]) {
      dt[now << 1] = wp[now];
      dt[now << 1 | 1] = wp[now];
      wp[now << 1] = wp[now];
      wp[now << 1 | 1] = wp[now];
      wp[now] = 0;
    }
  }
  void inline pu(int now) { dt[now] = min(dt[now << 1], dt[now << 1 | 1]); }
  void add(int l, int r, int x, int now = 1, int nl = 0,
           int nr = (1 << 18) - 1) {
    if (nl >= l && nr <= r) return void((dt[now] = x, wp[now] = x));
    if (nl > r || nr < l) return;
    pd(now);
    int m = (nl + nr) >> 1;
    add(l, r, x, now << 1, nl, m);
    add(l, r, x, now << 1 | 1, m + 1, nr);
    pu(now);
  }
  int qry(int l, int r, int now = 1, int nl = 0, int nr = (1 << 18) - 1) {
    if (nl >= l && nr <= r) return dt[now];
    if (nl > r || nr < l) return Inf;
    pd(now);
    int m = (nl + nr) >> 1;
    return min(qry(l, r, now << 1, nl, m), qry(l, r, now << 1 | 1, m + 1, nr));
  }
} psg, seg;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= (n); i++) scanf("%d", b + i);
  scanf("%d", &q);
  vector<int> lss;
  for (int i = 1; i <= (q); i++) {
    scanf("%d", mode + i);
    if (mode[i] == 1)
      scanf("%d%d%d", l + i, r + i, x + i);
    else
      scanf("%d%d", l + i, r + i);
    lss.push_back(l[i]);
    lss.push_back(r[i] + 1);
  }
  lss.push_back(1);
  lss.push_back(n * k + 1);
  for (int i = 0; i < (n); i++) psg.add(i, i, b[i + 1]);
  sort((lss).begin(), (lss).end());
  lss.resize(unique((lss).begin(), (lss).end()) - lss.begin());
  m = lss.size() - 1;
  for (int i = 0; i < (m); i++) {
    int now = lss[i] - 1, nxt = lss[i + 1] - 2;
    if (nxt - now + 1 >= n)
      seg.add(i, i, psg.qry(0, n - 1));
    else if (now % n <= nxt % n)
      seg.add(i, i, psg.qry(now % n, nxt % n));
    else
      seg.add(i, i, min(psg.qry(now % n, n - 1), psg.qry(0, nxt % n)));
  }
  for (int i = 1; i <= (q); i++) {
    l[i] = lower_bound((lss).begin(), (lss).end(), l[i]) - lss.begin();
    r[i] = upper_bound((lss).begin(), (lss).end(), r[i]) - lss.begin() - 1;
    if (mode[i] == 1)
      seg.add(l[i], r[i], x[i]);
    else
      printf("%d\n", seg.qry(l[i], r[i]));
  }
  return 0;
}

```