#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 5;
const int mod = 998244353;
struct segmentree {
  int tree[N * 4];
  int lazy[N * 4];
  void pushdown(int id) {
    if (lazy[id]) {
      tree[id << 1] = tree[id << 1 | 1] = lazy[id << 1] = lazy[id << 1 | 1] =
          lazy[id];
      lazy[id] = 0;
    }
    return;
  }
  void pushup(int id) { tree[id] = min(tree[id << 1], tree[id << 1 | 1]); }
  void update(int l, int r, int x, int y, int v, int id) {
    pushdown(id);
    if (x <= l && r <= y) {
      tree[id] = lazy[id] = v;
      return;
    }
    int mid = (l + r) >> 1;
    if (x <= mid) update(l, mid, x, y, v, id << 1);
    if (mid < y) update(mid + 1, r, x, y, v, id << 1 | 1);
    pushup(id);
    return;
  }
  int query(int l, int r, int x, int y, int id) {
    int res = 1e9;
    pushdown(id);
    if (x <= l && r <= y) return tree[id];
    int mid = (l + r) >> 1;
    if (x <= mid) res = query(l, mid, x, y, id << 1);
    if (mid < y) res = min(res, query(mid + 1, r, x, y, id << 1 | 1));
    return res;
  }
} x, y;
int n, k, q, a[N], l[N], r[N], t[N], p[N], sz;
map<int, int> mp;
vector<int> v;
int qwq(int L, int R) {
  if (!L) L++;
  if (!R) R++;
  if (R - L + 1 >= n) return x.query(1, n, 1, n, 1);
  if ((L - 1) % n > (R - 1) % n)
    return min(x.query(1, n, (L - 1) % n + 1, n, 1),
               x.query(1, n, 1, (R - 1) % n + 1, 1));
  else
    return x.query(1, n, (L - 1) % n + 1, (R - 1) % n + 1, 1);
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i], x.update(1, n, i, i, a[i], 1);
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> t[i] >> l[i] >> r[i];
    v.push_back(l[i] - 1), v.push_back(r[i]);
    if (t[i] == 1) cin >> p[i];
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  sz = v.size();
  for (int i = 0; i < sz; i++) mp[v[i]] = i + 1;
  for (int i = 0; i < q; i++) l[i] = mp[l[i] - 1], r[i] = mp[r[i]];
  for (int i = 1; i <= sz; i++)
    y.update(1, sz, i, i, qwq((i == 1 ? 0 : v[i - 2]) + 1, v[i - 1]), 1);
  for (int i = 0; i < q; i++) {
    if (t[i] == 1) {
      y.update(1, sz, l[i] + 1, r[i], p[i], 1);
    } else {
      cout << y.query(1, sz, l[i] + 1, r[i], 1) << "\n";
    }
  }
  return 0;
}

### Prompt

Generate 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 = 4e5 + 5;
const int mod = 998244353;
struct segmentree {
  int tree[N * 4];
  int lazy[N * 4];
  void pushdown(int id) {
    if (lazy[id]) {
      tree[id << 1] = tree[id << 1 | 1] = lazy[id << 1] = lazy[id << 1 | 1] =
          lazy[id];
      lazy[id] = 0;
    }
    return;
  }
  void pushup(int id) { tree[id] = min(tree[id << 1], tree[id << 1 | 1]); }
  void update(int l, int r, int x, int y, int v, int id) {
    pushdown(id);
    if (x <= l && r <= y) {
      tree[id] = lazy[id] = v;
      return;
    }
    int mid = (l + r) >> 1;
    if (x <= mid) update(l, mid, x, y, v, id << 1);
    if (mid < y) update(mid + 1, r, x, y, v, id << 1 | 1);
    pushup(id);
    return;
  }
  int query(int l, int r, int x, int y, int id) {
    int res = 1e9;
    pushdown(id);
    if (x <= l && r <= y) return tree[id];
    int mid = (l + r) >> 1;
    if (x <= mid) res = query(l, mid, x, y, id << 1);
    if (mid < y) res = min(res, query(mid + 1, r, x, y, id << 1 | 1));
    return res;
  }
} x, y;
int n, k, q, a[N], l[N], r[N], t[N], p[N], sz;
map<int, int> mp;
vector<int> v;
int qwq(int L, int R) {
  if (!L) L++;
  if (!R) R++;
  if (R - L + 1 >= n) return x.query(1, n, 1, n, 1);
  if ((L - 1) % n > (R - 1) % n)
    return min(x.query(1, n, (L - 1) % n + 1, n, 1),
               x.query(1, n, 1, (R - 1) % n + 1, 1));
  else
    return x.query(1, n, (L - 1) % n + 1, (R - 1) % n + 1, 1);
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i], x.update(1, n, i, i, a[i], 1);
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> t[i] >> l[i] >> r[i];
    v.push_back(l[i] - 1), v.push_back(r[i]);
    if (t[i] == 1) cin >> p[i];
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  sz = v.size();
  for (int i = 0; i < sz; i++) mp[v[i]] = i + 1;
  for (int i = 0; i < q; i++) l[i] = mp[l[i] - 1], r[i] = mp[r[i]];
  for (int i = 1; i <= sz; i++)
    y.update(1, sz, i, i, qwq((i == 1 ? 0 : v[i - 2]) + 1, v[i - 1]), 1);
  for (int i = 0; i < q; i++) {
    if (t[i] == 1) {
      y.update(1, sz, l[i] + 1, r[i], p[i], 1);
    } else {
      cout << y.query(1, sz, l[i] + 1, r[i], 1) << "\n";
    }
  }
  return 0;
}

```