#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 500017;
const int MAXL = 21;
const int MAXS = MAXN * 4;
const int MAX = 524288;
class stT {
 public:
  stT() { memset(data, 0x3f3f3f3f, sizeof(data)); }
  void upd(int l, int r, int x, int now = 1, int ll = 1, int rr = MAX) {
    if (l > r) return;
    if (ll >= l && rr <= r)
      tag[now] = data[now] = x;
    else if (rr < l || ll > r)
      return;
    else {
      int mid = (ll + rr) >> 1;
      downtag(now);
      upd(l, r, x, now << 1, ll, mid);
      upd(l, r, x, now << 1 | 1, mid + 1, rr);
      data[now] =
          (((data[now << 1]) < (data[now << 1 | 1])) ? (data[now << 1])
                                                     : (data[now << 1 | 1]));
    }
  }
  int query(int l, int r, int now = 1, int ll = 1, int rr = MAX) {
    if (l > r) return INF;
    if (ll >= l && rr <= r)
      return data[now];
    else if (rr < l || ll > r)
      return INF;
    else {
      int mid = (ll + rr) >> 1;
      downtag(now);
      return min(query(l, r, now << 1, ll, mid),
                 query(l, r, now << 1 | 1, mid + 1, rr));
    }
  }

 private:
  void downtag(int now) {
    if (tag[now]) {
      tag[now << 1] = tag[now << 1 | 1] = data[now << 1] = data[now << 1 | 1] =
          tag[now];
      tag[now] = 0;
    }
  }
  int tag[MAXS], data[MAXS];
} st;
struct qT {
  void input() {
    scanf("%d%d%d", &tp, &l, &r);
    if (tp == 1) scanf("%d", &x);
  }
  int tp, l, r, x;
} que[MAXN];
int n, nk, m, q;
int a[MAXN];
int rmq[MAXN][MAXL];
int qlg[MAXN];
set<int> pt;
map<int, int> rid;
void init();
void input();
void work();
void add(int l, int r, int x);
int query(int l, int r);
int rmqreq(int l, int r);
int _rmqreq(int l, int r);
int main() {
  init();
  input();
  work();
}
void init() {
  ios::sync_with_stdio(false);
  qlg[0] = qlg[1] = 0;
  for (int i = 2; i < MAXN; ++i) qlg[i] = qlg[i >> 1] + 1;
}
void input() {
  scanf("%d%d", &n, &nk);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  scanf("%d", &q);
  for (int i = 1; i <= q; ++i) que[i].input();
}
void work() {
  m = nk * n;
  for (int i = 1; i <= n; ++i) rmq[i][0] = a[i];
  for (int j = 1; j < MAXL; ++j)
    for (int i = 1; i <= n - (1 << (j - 1)); ++i)
      rmq[i][j] = (((rmq[i][j - 1]) < (rmq[i + (1 << (j - 1))][j - 1]))
                       ? (rmq[i][j - 1])
                       : (rmq[i + (1 << (j - 1))][j - 1]));
  for (int i = 1; i <= q; ++i)
    pt.insert(que[i].l), pt.insert(que[i].l + 1), pt.insert(que[i].r),
        pt.insert(que[i].r + 1);
  pt.insert(0);
  pt.insert(m + 1);
  int cc = 1, la = -1;
  for (auto x : pt) {
    if (~la) st.upd(cc - 1, cc - 1, rmqreq(la, x - 1));
    rid[x] = cc, ++cc;
    la = x;
  }
  for (int i = 1; i <= q; ++i) {
    if (que[i].tp == 1)
      add(que[i].l, que[i].r, que[i].x);
    else
      printf("%d\n", query(que[i].l, que[i].r));
  }
}
void add(int l, int r, int x) {
  int il = rid.find(l)->second, ir = rid.find(r)->second;
  st.upd(il, ir, x);
}
int query(int l, int r) {
  int il = rid.find(l)->second, ir = rid.find(r)->second;
  return st.query(il, ir);
}
int rmqreq(int l, int r) {
  int bl = (l - 1) / n, br = (r - 1) / n;
  if (br - bl > 1) return _rmqreq(1, n);
  int il = (l - 1) % n + 1, ir = (r - 1) % n + 1;
  if (br == bl)
    return _rmqreq(il, ir);
  else
    return min(_rmqreq(il, n), _rmqreq(1, ir));
}
int _rmqreq(int l, int r) {
  int g = qlg[r - l + 1];
  return (((rmq[l][g]) < (rmq[r - (1 << g) + 1][g]))
              ? (rmq[l][g])
              : (rmq[r - (1 << g) + 1][g]));
}

### Prompt

In Cpp, your task is to solve 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 = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 500017;
const int MAXL = 21;
const int MAXS = MAXN * 4;
const int MAX = 524288;
class stT {
 public:
  stT() { memset(data, 0x3f3f3f3f, sizeof(data)); }
  void upd(int l, int r, int x, int now = 1, int ll = 1, int rr = MAX) {
    if (l > r) return;
    if (ll >= l && rr <= r)
      tag[now] = data[now] = x;
    else if (rr < l || ll > r)
      return;
    else {
      int mid = (ll + rr) >> 1;
      downtag(now);
      upd(l, r, x, now << 1, ll, mid);
      upd(l, r, x, now << 1 | 1, mid + 1, rr);
      data[now] =
          (((data[now << 1]) < (data[now << 1 | 1])) ? (data[now << 1])
                                                     : (data[now << 1 | 1]));
    }
  }
  int query(int l, int r, int now = 1, int ll = 1, int rr = MAX) {
    if (l > r) return INF;
    if (ll >= l && rr <= r)
      return data[now];
    else if (rr < l || ll > r)
      return INF;
    else {
      int mid = (ll + rr) >> 1;
      downtag(now);
      return min(query(l, r, now << 1, ll, mid),
                 query(l, r, now << 1 | 1, mid + 1, rr));
    }
  }

 private:
  void downtag(int now) {
    if (tag[now]) {
      tag[now << 1] = tag[now << 1 | 1] = data[now << 1] = data[now << 1 | 1] =
          tag[now];
      tag[now] = 0;
    }
  }
  int tag[MAXS], data[MAXS];
} st;
struct qT {
  void input() {
    scanf("%d%d%d", &tp, &l, &r);
    if (tp == 1) scanf("%d", &x);
  }
  int tp, l, r, x;
} que[MAXN];
int n, nk, m, q;
int a[MAXN];
int rmq[MAXN][MAXL];
int qlg[MAXN];
set<int> pt;
map<int, int> rid;
void init();
void input();
void work();
void add(int l, int r, int x);
int query(int l, int r);
int rmqreq(int l, int r);
int _rmqreq(int l, int r);
int main() {
  init();
  input();
  work();
}
void init() {
  ios::sync_with_stdio(false);
  qlg[0] = qlg[1] = 0;
  for (int i = 2; i < MAXN; ++i) qlg[i] = qlg[i >> 1] + 1;
}
void input() {
  scanf("%d%d", &n, &nk);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  scanf("%d", &q);
  for (int i = 1; i <= q; ++i) que[i].input();
}
void work() {
  m = nk * n;
  for (int i = 1; i <= n; ++i) rmq[i][0] = a[i];
  for (int j = 1; j < MAXL; ++j)
    for (int i = 1; i <= n - (1 << (j - 1)); ++i)
      rmq[i][j] = (((rmq[i][j - 1]) < (rmq[i + (1 << (j - 1))][j - 1]))
                       ? (rmq[i][j - 1])
                       : (rmq[i + (1 << (j - 1))][j - 1]));
  for (int i = 1; i <= q; ++i)
    pt.insert(que[i].l), pt.insert(que[i].l + 1), pt.insert(que[i].r),
        pt.insert(que[i].r + 1);
  pt.insert(0);
  pt.insert(m + 1);
  int cc = 1, la = -1;
  for (auto x : pt) {
    if (~la) st.upd(cc - 1, cc - 1, rmqreq(la, x - 1));
    rid[x] = cc, ++cc;
    la = x;
  }
  for (int i = 1; i <= q; ++i) {
    if (que[i].tp == 1)
      add(que[i].l, que[i].r, que[i].x);
    else
      printf("%d\n", query(que[i].l, que[i].r));
  }
}
void add(int l, int r, int x) {
  int il = rid.find(l)->second, ir = rid.find(r)->second;
  st.upd(il, ir, x);
}
int query(int l, int r) {
  int il = rid.find(l)->second, ir = rid.find(r)->second;
  return st.query(il, ir);
}
int rmqreq(int l, int r) {
  int bl = (l - 1) / n, br = (r - 1) / n;
  if (br - bl > 1) return _rmqreq(1, n);
  int il = (l - 1) % n + 1, ir = (r - 1) % n + 1;
  if (br == bl)
    return _rmqreq(il, ir);
  else
    return min(_rmqreq(il, n), _rmqreq(1, ir));
}
int _rmqreq(int l, int r) {
  int g = qlg[r - l + 1];
  return (((rmq[l][g]) < (rmq[r - (1 << g) + 1][g]))
              ? (rmq[l][g])
              : (rmq[r - (1 << g) + 1][g]));
}

```