#include <bits/stdc++.h>
using namespace std;
static inline void canhazfast() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
template <typename T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <typename T>
T extgcd(T a, T b, T &x, T &y) {
  T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
  while (b) {
    T q = a / b;
    a %= b;
    swap(a, b);
    x0 -= q * x1;
    swap(x0, x1);
    y0 -= q * y1;
    swap(y0, y1);
  }
  x = x0;
  y = y0;
  return a;
}
int ctz(unsigned x) { return __builtin_ctz(x); }
int ctzll(unsigned long long x) { return __builtin_ctzll(x); }
int clz(unsigned x) { return __builtin_clz(x); }
int clzll(unsigned long long x) { return __builtin_clzll(x); }
int popcnt(unsigned x) { return __builtin_popcount(x); }
int popcntll(unsigned long long x) { return __builtin_popcountll(x); }
int bsr(unsigned x) { return 31 ^ clz(x); }
int bsrll(unsigned long long x) { return 63 ^ clzll(x); }
int c[200016], pre[200016], suf[200016];
int ql[200016], qr[200016], qt[200016], qx[200016];
int pos[200016];
int tree_old[(1 << 19)];
int lazy[(1 << 19)];
int tree[(1 << 19)];
int lookup(int x, int m) { return lower_bound(pos, pos + m, x) - pos; }
void build_old(int u, int b, int e) {
  if (b + 1 == e) return void(tree_old[u] = c[b]);
  int m = (b + e) / 2, lc = 2 * u, rc = 2 * u + 1;
  build_old(lc, b, m);
  build_old(rc, m, e);
  tree_old[u] = min(tree_old[lc], tree_old[rc]);
}
int get_old(int u, int b, int e, int l, int r) {
  if (b >= r || l >= e) return 1123456789;
  if (b >= l && r >= e) return tree_old[u];
  int m = (b + e) / 2, lc = 2 * u, rc = 2 * u + 1;
  return min(get_old(lc, b, m, l, r), get_old(rc, m, e, l, r));
}
void build(int u, int b, int e, int n) {
  if (b + 1 == e) {
    int l = pos[b], r = pos[e];
    if (r - l >= n) return void(tree[u] = pre[n]);
    int lq = l / n, li = l % n;
    int rq = r / n, ri = r % n;
    if (lq != rq)
      tree[u] = min(suf[li], pre[ri]);
    else
      tree[u] = get_old(1, 0, n, li, ri);
    return;
  }
  int m = (b + e) / 2, lc = 2 * u, rc = 2 * u + 1;
  build(lc, b, m, n);
  build(rc, m, e, n);
  tree[u] = min(tree[lc], tree[rc]);
}
void update(int u, int b, int e, int l, int r, int x) {
  if (b >= r || l >= e) return;
  if (b >= l && r >= e) return void(tree[u] = lazy[u] = x);
  int m = (b + e) / 2, lc = 2 * u, rc = 2 * u + 1;
  if (lazy[u]) {
    tree[lc] = lazy[lc] = lazy[u];
    tree[rc] = lazy[rc] = lazy[u];
    lazy[u] = 0;
  }
  update(lc, b, m, l, r, x);
  update(rc, m, e, l, r, x);
  tree[u] = min(tree[lc], tree[rc]);
}
int query(int u, int b, int e, int l, int r) {
  if (b >= r || l >= e) return 1123456789;
  if (b >= l && r >= e) return tree[u];
  int m = (b + e) / 2, lc = 2 * u, rc = 2 * u + 1;
  if (lazy[u]) {
    tree[lc] = lazy[lc] = lazy[u];
    tree[rc] = lazy[rc] = lazy[u];
    lazy[u] = 0;
  }
  return min(query(lc, b, m, l, r), query(rc, m, e, l, r));
}
int main() {
  canhazfast();
  int n, k, q, m = 0;
  cin >> n >> k;
  pre[0] = 1123456789;
  for (int i = 0; i < n; ++i) {
    cin >> c[i];
    pre[i + 1] = min(pre[i], c[i]);
  }
  suf[n] = 1123456789;
  for (int i = n - 1; i >= 0; --i) suf[i] = min(suf[i + 1], c[i]);
  build_old(1, 0, n);
  cin >> q;
  for (int i = 0; i < q; ++i) {
    cin >> qt[i] >> ql[i] >> qr[i];
    --ql[i];
    if (qt[i] == 1) cin >> qx[i];
    pos[m++] = ql[i];
    pos[m++] = qr[i];
  }
  pos[m++] = 0;
  pos[m++] = n * k;
  sort(pos, pos + m);
  m = unique(pos, pos + m) - pos - 1;
  build(1, 0, m, n);
  for (int i = 0; i < q; ++i) {
    int l = lookup(ql[i], m);
    int r = lookup(qr[i], m);
    if (qt[i] == 1)
      update(1, 0, m, l, r, qx[i]);
    else
      cout << query(1, 0, m, l, r) << '\n';
  }
  return 0;
}

### Prompt

Your task is to create 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;
static inline void canhazfast() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
template <typename T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <typename T>
T extgcd(T a, T b, T &x, T &y) {
  T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
  while (b) {
    T q = a / b;
    a %= b;
    swap(a, b);
    x0 -= q * x1;
    swap(x0, x1);
    y0 -= q * y1;
    swap(y0, y1);
  }
  x = x0;
  y = y0;
  return a;
}
int ctz(unsigned x) { return __builtin_ctz(x); }
int ctzll(unsigned long long x) { return __builtin_ctzll(x); }
int clz(unsigned x) { return __builtin_clz(x); }
int clzll(unsigned long long x) { return __builtin_clzll(x); }
int popcnt(unsigned x) { return __builtin_popcount(x); }
int popcntll(unsigned long long x) { return __builtin_popcountll(x); }
int bsr(unsigned x) { return 31 ^ clz(x); }
int bsrll(unsigned long long x) { return 63 ^ clzll(x); }
int c[200016], pre[200016], suf[200016];
int ql[200016], qr[200016], qt[200016], qx[200016];
int pos[200016];
int tree_old[(1 << 19)];
int lazy[(1 << 19)];
int tree[(1 << 19)];
int lookup(int x, int m) { return lower_bound(pos, pos + m, x) - pos; }
void build_old(int u, int b, int e) {
  if (b + 1 == e) return void(tree_old[u] = c[b]);
  int m = (b + e) / 2, lc = 2 * u, rc = 2 * u + 1;
  build_old(lc, b, m);
  build_old(rc, m, e);
  tree_old[u] = min(tree_old[lc], tree_old[rc]);
}
int get_old(int u, int b, int e, int l, int r) {
  if (b >= r || l >= e) return 1123456789;
  if (b >= l && r >= e) return tree_old[u];
  int m = (b + e) / 2, lc = 2 * u, rc = 2 * u + 1;
  return min(get_old(lc, b, m, l, r), get_old(rc, m, e, l, r));
}
void build(int u, int b, int e, int n) {
  if (b + 1 == e) {
    int l = pos[b], r = pos[e];
    if (r - l >= n) return void(tree[u] = pre[n]);
    int lq = l / n, li = l % n;
    int rq = r / n, ri = r % n;
    if (lq != rq)
      tree[u] = min(suf[li], pre[ri]);
    else
      tree[u] = get_old(1, 0, n, li, ri);
    return;
  }
  int m = (b + e) / 2, lc = 2 * u, rc = 2 * u + 1;
  build(lc, b, m, n);
  build(rc, m, e, n);
  tree[u] = min(tree[lc], tree[rc]);
}
void update(int u, int b, int e, int l, int r, int x) {
  if (b >= r || l >= e) return;
  if (b >= l && r >= e) return void(tree[u] = lazy[u] = x);
  int m = (b + e) / 2, lc = 2 * u, rc = 2 * u + 1;
  if (lazy[u]) {
    tree[lc] = lazy[lc] = lazy[u];
    tree[rc] = lazy[rc] = lazy[u];
    lazy[u] = 0;
  }
  update(lc, b, m, l, r, x);
  update(rc, m, e, l, r, x);
  tree[u] = min(tree[lc], tree[rc]);
}
int query(int u, int b, int e, int l, int r) {
  if (b >= r || l >= e) return 1123456789;
  if (b >= l && r >= e) return tree[u];
  int m = (b + e) / 2, lc = 2 * u, rc = 2 * u + 1;
  if (lazy[u]) {
    tree[lc] = lazy[lc] = lazy[u];
    tree[rc] = lazy[rc] = lazy[u];
    lazy[u] = 0;
  }
  return min(query(lc, b, m, l, r), query(rc, m, e, l, r));
}
int main() {
  canhazfast();
  int n, k, q, m = 0;
  cin >> n >> k;
  pre[0] = 1123456789;
  for (int i = 0; i < n; ++i) {
    cin >> c[i];
    pre[i + 1] = min(pre[i], c[i]);
  }
  suf[n] = 1123456789;
  for (int i = n - 1; i >= 0; --i) suf[i] = min(suf[i + 1], c[i]);
  build_old(1, 0, n);
  cin >> q;
  for (int i = 0; i < q; ++i) {
    cin >> qt[i] >> ql[i] >> qr[i];
    --ql[i];
    if (qt[i] == 1) cin >> qx[i];
    pos[m++] = ql[i];
    pos[m++] = qr[i];
  }
  pos[m++] = 0;
  pos[m++] = n * k;
  sort(pos, pos + m);
  m = unique(pos, pos + m) - pos - 1;
  build(1, 0, m, n);
  for (int i = 0; i < q; ++i) {
    int l = lookup(ql[i], m);
    int r = lookup(qr[i], m);
    if (qt[i] == 1)
      update(1, 0, m, l, r, qx[i]);
    else
      cout << query(1, 0, m, l, r) << '\n';
  }
  return 0;
}

```