#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U>
ostream& operator<<(ostream& o, const pair<T, U>& p) {
  o << "(" << p.first << "," << p.second << ")";
  return o;
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& v) {
  o << "[";
  for (T t : v) {
    o << t << ",";
  }
  o << "]";
  return o;
}
struct LazySegTree {
  int n;
  vector<ll> dat, lazy;
  LazySegTree(int _n) {
    n = 1;
    while (n < _n) n *= 2;
    dat = vector<ll>(2 * n - 1, LLONG_MAX / 2);
    lazy = vector<ll>(2 * n - 1, 0);
  }
  void show() {
    for (int(j) = 0; (j) < (int)(dat.size()); ++(j))
      printf(" %d: dat= %lld, lazy= %lld\n", j, dat[j], lazy[j]);
  }
  void setLazy(int k, ll v) {
    lazy[k] = v;
    dat[k] = v;
  }
  void push(int k, int l, int r) {
    if (lazy[k] != 0) {
      setLazy(2 * k + 1, lazy[k]);
      setLazy(2 * k + 2, lazy[k]);
    }
    lazy[k] = 0;
  }
  void fix(int k, int l, int r) {
    dat[k] = min(dat[2 * k + 1], dat[2 * k + 2]);
  }
  ll merge(ll x, ll y) { return min(x, y); }
  void _update(int a, int b, ll x, int k, int l, int r) {
    if (r <= a || b <= l) return;
    if (a <= l && r <= b) {
      setLazy(k, x);
      return;
    }
    push(k, l, r);
    _update(a, b, x, 2 * k + 1, l, (l + r) / 2);
    _update(a, b, x, 2 * k + 2, (l + r) / 2, r);
    fix(k, l, r);
  }
  void update(int a, int b, ll x) { return _update(a, b, x, 0, 0, n); }
  ll _query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return LLONG_MAX / 2;
    if (a <= l && r <= b) return dat[k];
    push(k, l, r);
    ll vl = _query(a, b, 2 * k + 1, l, (l + r) / 2);
    ll vr = _query(a, b, 2 * k + 2, (l + r) / 2, r);
    return merge(vl, vr);
  }
  ll query(int a, int b) { return _query(a, b, 0, 0, n); }
};
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> b(n);
  for (int(i) = 0; (i) < (int)(n); ++(i)) cin >> b[i];
  int q;
  cin >> q;
  vector<int> t(q), l(q), r(q), x(q, -1);
  for (int(i) = 0; (i) < (int)(q); ++(i)) {
    cin >> t[i] >> l[i] >> r[i];
    --l[i];
    --r[i];
    if (t[i] == 1) cin >> x[i];
  }
  vector<int> idx;
  for (int(i) = 0; (i) < (int)(q); ++(i)) {
    idx.push_back(l[i]);
    idx.push_back(r[i]);
  }
  idx.push_back(0);
  idx.push_back(n * k - 1);
  sort((idx).begin(), (idx).end());
  idx.erase(unique((idx).begin(), (idx).end()), idx.end());
  LazySegTree one(n);
  for (int(i) = 0; (i) < (int)(n); ++(i)) one.update(i, i + 1, b[i]);
  map<int, int> m;
  vector<int> comp;
  comp.push_back(b[0]);
  m[0] = 0;
  for (int i = 1; i < idx.size(); ++i) {
    if (idx[i] - idx[i - 1] > 1) {
      int L = (idx[i - 1] + 1) % n, R = (idx[i] + n - 1) % n;
      int v;
      if (L <= R)
        v = one.query(L, R + 1);
      else
        v = min(one.query(0, R + 1), one.query(L, n));
      comp.push_back(v);
    }
    m[idx[i]] = comp.size();
    comp.push_back(b[idx[i] % n]);
  }
  LazySegTree st(comp.size());
  for (int(i) = 0; (i) < (int)(comp.size()); ++(i))
    st.update(i, i + 1, comp[i]);
  for (int(i) = 0; (i) < (int)(q); ++(i)) {
    int L = m[l[i]], R = m[r[i]];
    if (t[i] == 1)
      st.update(L, R + 1, x[i]);
    else
      cout << st.query(L, R + 1) << endl;
  }
  return 0;
}

### Prompt

Please provide a CPP coded solution to the problem described below:

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;
using ll = long long;
template <class T, class U>
ostream& operator<<(ostream& o, const pair<T, U>& p) {
  o << "(" << p.first << "," << p.second << ")";
  return o;
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& v) {
  o << "[";
  for (T t : v) {
    o << t << ",";
  }
  o << "]";
  return o;
}
struct LazySegTree {
  int n;
  vector<ll> dat, lazy;
  LazySegTree(int _n) {
    n = 1;
    while (n < _n) n *= 2;
    dat = vector<ll>(2 * n - 1, LLONG_MAX / 2);
    lazy = vector<ll>(2 * n - 1, 0);
  }
  void show() {
    for (int(j) = 0; (j) < (int)(dat.size()); ++(j))
      printf(" %d: dat= %lld, lazy= %lld\n", j, dat[j], lazy[j]);
  }
  void setLazy(int k, ll v) {
    lazy[k] = v;
    dat[k] = v;
  }
  void push(int k, int l, int r) {
    if (lazy[k] != 0) {
      setLazy(2 * k + 1, lazy[k]);
      setLazy(2 * k + 2, lazy[k]);
    }
    lazy[k] = 0;
  }
  void fix(int k, int l, int r) {
    dat[k] = min(dat[2 * k + 1], dat[2 * k + 2]);
  }
  ll merge(ll x, ll y) { return min(x, y); }
  void _update(int a, int b, ll x, int k, int l, int r) {
    if (r <= a || b <= l) return;
    if (a <= l && r <= b) {
      setLazy(k, x);
      return;
    }
    push(k, l, r);
    _update(a, b, x, 2 * k + 1, l, (l + r) / 2);
    _update(a, b, x, 2 * k + 2, (l + r) / 2, r);
    fix(k, l, r);
  }
  void update(int a, int b, ll x) { return _update(a, b, x, 0, 0, n); }
  ll _query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return LLONG_MAX / 2;
    if (a <= l && r <= b) return dat[k];
    push(k, l, r);
    ll vl = _query(a, b, 2 * k + 1, l, (l + r) / 2);
    ll vr = _query(a, b, 2 * k + 2, (l + r) / 2, r);
    return merge(vl, vr);
  }
  ll query(int a, int b) { return _query(a, b, 0, 0, n); }
};
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> b(n);
  for (int(i) = 0; (i) < (int)(n); ++(i)) cin >> b[i];
  int q;
  cin >> q;
  vector<int> t(q), l(q), r(q), x(q, -1);
  for (int(i) = 0; (i) < (int)(q); ++(i)) {
    cin >> t[i] >> l[i] >> r[i];
    --l[i];
    --r[i];
    if (t[i] == 1) cin >> x[i];
  }
  vector<int> idx;
  for (int(i) = 0; (i) < (int)(q); ++(i)) {
    idx.push_back(l[i]);
    idx.push_back(r[i]);
  }
  idx.push_back(0);
  idx.push_back(n * k - 1);
  sort((idx).begin(), (idx).end());
  idx.erase(unique((idx).begin(), (idx).end()), idx.end());
  LazySegTree one(n);
  for (int(i) = 0; (i) < (int)(n); ++(i)) one.update(i, i + 1, b[i]);
  map<int, int> m;
  vector<int> comp;
  comp.push_back(b[0]);
  m[0] = 0;
  for (int i = 1; i < idx.size(); ++i) {
    if (idx[i] - idx[i - 1] > 1) {
      int L = (idx[i - 1] + 1) % n, R = (idx[i] + n - 1) % n;
      int v;
      if (L <= R)
        v = one.query(L, R + 1);
      else
        v = min(one.query(0, R + 1), one.query(L, n));
      comp.push_back(v);
    }
    m[idx[i]] = comp.size();
    comp.push_back(b[idx[i] % n]);
  }
  LazySegTree st(comp.size());
  for (int(i) = 0; (i) < (int)(comp.size()); ++(i))
    st.update(i, i + 1, comp[i]);
  for (int(i) = 0; (i) < (int)(q); ++(i)) {
    int L = m[l[i]], R = m[r[i]];
    if (t[i] == 1)
      st.update(L, R + 1, x[i]);
    else
      cout << st.query(L, R + 1) << endl;
  }
  return 0;
}

```