#include <bits/stdc++.h>
using namespace std;
const int Inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
struct Segtree {
  int dt[1 << 20], wp[1 << 20];
  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 inline 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 inline get(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(get(l, r, now << 1, nl, m), get(l, r, now << 1 | 1, m + 1, nr));
  }
} seg, sg;
template <typename num>
struct Lissan {
  vector<num> lss;
  bool built;
  num inline operator[](int id) { return lss[id]; }
  void inline clear() {
    lss.clear();
    built = 0;
  }
  void inline add(num x) { lss.push_back(x); }
  void inline build() {
    sort((lss).begin(), (lss).end());
    lss.erase(unique((lss).begin(), (lss).end()), lss.end());
    built = 1;
  }
  int inline size() {
    assert(built);
    return ((int)(lss).size());
  }
  int inline get(num x, int th = 0) {
    assert(built);
    return lower_bound((lss).begin(), (lss).end(), x) - lss.begin() + th;
  }
};
const int qwq = 1 << 17;
int n, k, q, m;
int a[qwq];
int mode[qwq], l[qwq], r[qwq], x[qwq];
Lissan<int> lss;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= (n); ++i) scanf("%d", a + i);
  scanf("%d", &q);
  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.add(l[i]);
    lss.add(r[i] + 1);
  }
  lss.add(1);
  lss.add(n * k + 1);
  lss.build();
  m = ((int)(lss).size()) - 1;
  for (int i = 0; i < (n); ++i) seg.add(i, i, a[i + 1]);
  for (int i = 0; i < (m); ++i) {
    int l = lss[i] - 1, r = lss[i + 1] - 2;
    if (r - l + 1 >= n)
      sg.add(i, i, seg.get(0, n - 1));
    else if (l % n <= r % n)
      sg.add(i, i, seg.get(l % n, r % n));
    else
      sg.add(i, i, min(seg.get(l % n, n - 1), seg.get(0, r % n)));
  }
  for (int i = 1; i <= (q); ++i) {
    int ls = lss.get(l[i]), rs = lss.get(r[i] + 1) - 1;
    if (mode[i] == 1)
      sg.add(ls, rs, x[i]);
    else
      printf("%d\n", sg.get(ls, rs));
  }
  return 0;
}

### Prompt

Your challenge is to write 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 Inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
struct Segtree {
  int dt[1 << 20], wp[1 << 20];
  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 inline 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 inline get(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(get(l, r, now << 1, nl, m), get(l, r, now << 1 | 1, m + 1, nr));
  }
} seg, sg;
template <typename num>
struct Lissan {
  vector<num> lss;
  bool built;
  num inline operator[](int id) { return lss[id]; }
  void inline clear() {
    lss.clear();
    built = 0;
  }
  void inline add(num x) { lss.push_back(x); }
  void inline build() {
    sort((lss).begin(), (lss).end());
    lss.erase(unique((lss).begin(), (lss).end()), lss.end());
    built = 1;
  }
  int inline size() {
    assert(built);
    return ((int)(lss).size());
  }
  int inline get(num x, int th = 0) {
    assert(built);
    return lower_bound((lss).begin(), (lss).end(), x) - lss.begin() + th;
  }
};
const int qwq = 1 << 17;
int n, k, q, m;
int a[qwq];
int mode[qwq], l[qwq], r[qwq], x[qwq];
Lissan<int> lss;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= (n); ++i) scanf("%d", a + i);
  scanf("%d", &q);
  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.add(l[i]);
    lss.add(r[i] + 1);
  }
  lss.add(1);
  lss.add(n * k + 1);
  lss.build();
  m = ((int)(lss).size()) - 1;
  for (int i = 0; i < (n); ++i) seg.add(i, i, a[i + 1]);
  for (int i = 0; i < (m); ++i) {
    int l = lss[i] - 1, r = lss[i + 1] - 2;
    if (r - l + 1 >= n)
      sg.add(i, i, seg.get(0, n - 1));
    else if (l % n <= r % n)
      sg.add(i, i, seg.get(l % n, r % n));
    else
      sg.add(i, i, min(seg.get(l % n, n - 1), seg.get(0, r % n)));
  }
  for (int i = 1; i <= (q); ++i) {
    int ls = lss.get(l[i]), rs = lss.get(r[i] + 1) - 1;
    if (mode[i] == 1)
      sg.add(ls, rs, x[i]);
    else
      printf("%d\n", sg.get(ls, rs));
  }
  return 0;
}

```