#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
const int maxm = maxn << 6;
int rd() {
  int tem;
  scanf("%d", &tem);
  return tem;
}
int n, k;
int a[maxn], tot, mi[maxm], ls[maxm], rs[maxm];
const int logm = 18;
int st[maxn][logm], tag[maxm];
inline void up(int x) { mi[x] = min(mi[ls[x]], mi[rs[x]]); }
inline void pre_st() {
  for (int j = 1; (1 << j) <= n; ++j) {
    for (int i = 1; i + (1 << j) - 1 <= n; ++i) {
      st[i][j] = min(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
    }
  }
}
int rmq(int l, int r) {
  int k = log2(r - l + 1);
  return min(st[l][k], st[r - (1 << k) + 1][k]);
}
int mii = inf;
inline int ask_st(int l, int r) {
  if (r - l + 1 >= n) return mii;
  l -= 1, r -= 1;
  l %= n, r %= n;
  l += 1, r += 1;
  if (l <= r) {
    return rmq(l, r);
  } else {
    return min(rmq(1, r), rmq(l, n));
  }
}
inline void sp(int x, int l, int r) {
  int mid = (l + r) >> 1;
  if (ls[x] == 0) {
    ls[x] = ++tot;
    mi[tot] = ask_st(l, mid);
  }
  if (rs[x] == 0) {
    rs[x] = ++tot;
    mi[tot] = ask_st(mid + 1, r);
  }
  if (!tag[x]) return;
  tag[ls[x]] = tag[rs[x]] = mi[rs[x]] = mi[ls[x]] = tag[x];
  tag[x] = 0;
}
inline void update(int x, int l, int r, int ql, int qr, int val) {
  if (l >= ql and r <= qr) {
    tag[x] = val;
    mi[x] = val;
    return;
  }
  sp(x, l, r);
  int mid = (l + r) >> 1;
  if (ql <= mid) update(ls[x], l, mid, ql, qr, val);
  if (qr > mid) update(rs[x], mid + 1, r, ql, qr, val);
  up(x);
}
inline int ask(int x, int l, int r, int ql, int qr) {
  if (l >= ql and r <= qr) return mi[x];
  int mid = (l + r) >> 1;
  sp(x, l, r);
  int tem = inf;
  if (ql <= mid) tem = min(tem, ask(ls[x], l, mid, ql, qr));
  if (qr > mid) tem = min(tem, ask(rs[x], mid + 1, r, ql, qr));
  return tem;
}
signed main() {
  cin >> n >> k;
  for (register int i = 1; i <= n; i++) {
    st[i][0] = a[i] = rd();
    mii = min(mii, a[i]);
  }
  pre_st();
  register int q;
  cin >> q;
  ++tot;
  mi[1] = mii;
  while (q--) {
    register int op = rd();
    if (op == 1) {
      register int x = rd(), y = rd(), val = rd();
      update(1, 1, n * k, x, y, val);
    } else {
      register int x = rd(), y = rd();
      cout << ask(1, 1, n * k, x, y) << '\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;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
const int maxm = maxn << 6;
int rd() {
  int tem;
  scanf("%d", &tem);
  return tem;
}
int n, k;
int a[maxn], tot, mi[maxm], ls[maxm], rs[maxm];
const int logm = 18;
int st[maxn][logm], tag[maxm];
inline void up(int x) { mi[x] = min(mi[ls[x]], mi[rs[x]]); }
inline void pre_st() {
  for (int j = 1; (1 << j) <= n; ++j) {
    for (int i = 1; i + (1 << j) - 1 <= n; ++i) {
      st[i][j] = min(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
    }
  }
}
int rmq(int l, int r) {
  int k = log2(r - l + 1);
  return min(st[l][k], st[r - (1 << k) + 1][k]);
}
int mii = inf;
inline int ask_st(int l, int r) {
  if (r - l + 1 >= n) return mii;
  l -= 1, r -= 1;
  l %= n, r %= n;
  l += 1, r += 1;
  if (l <= r) {
    return rmq(l, r);
  } else {
    return min(rmq(1, r), rmq(l, n));
  }
}
inline void sp(int x, int l, int r) {
  int mid = (l + r) >> 1;
  if (ls[x] == 0) {
    ls[x] = ++tot;
    mi[tot] = ask_st(l, mid);
  }
  if (rs[x] == 0) {
    rs[x] = ++tot;
    mi[tot] = ask_st(mid + 1, r);
  }
  if (!tag[x]) return;
  tag[ls[x]] = tag[rs[x]] = mi[rs[x]] = mi[ls[x]] = tag[x];
  tag[x] = 0;
}
inline void update(int x, int l, int r, int ql, int qr, int val) {
  if (l >= ql and r <= qr) {
    tag[x] = val;
    mi[x] = val;
    return;
  }
  sp(x, l, r);
  int mid = (l + r) >> 1;
  if (ql <= mid) update(ls[x], l, mid, ql, qr, val);
  if (qr > mid) update(rs[x], mid + 1, r, ql, qr, val);
  up(x);
}
inline int ask(int x, int l, int r, int ql, int qr) {
  if (l >= ql and r <= qr) return mi[x];
  int mid = (l + r) >> 1;
  sp(x, l, r);
  int tem = inf;
  if (ql <= mid) tem = min(tem, ask(ls[x], l, mid, ql, qr));
  if (qr > mid) tem = min(tem, ask(rs[x], mid + 1, r, ql, qr));
  return tem;
}
signed main() {
  cin >> n >> k;
  for (register int i = 1; i <= n; i++) {
    st[i][0] = a[i] = rd();
    mii = min(mii, a[i]);
  }
  pre_st();
  register int q;
  cin >> q;
  ++tot;
  mi[1] = mii;
  while (q--) {
    register int op = rd();
    if (op == 1) {
      register int x = rd(), y = rd(), val = rd();
      update(1, 1, n * k, x, y, val);
    } else {
      register int x = rd(), y = rd();
      cout << ask(1, 1, n * k, x, y) << '\n';
    }
  }
  return 0;
}

```