#include <bits/stdc++.h>
using namespace std;
int dat[100005];
struct RMQ {
  static constexpr int TSIZE = 131072;
  int tree[TSIZE * 2];
  void init(int n, int *d) {
    memcpy(tree + TSIZE, d, sizeof(int) * n);
    for (int i = TSIZE - 1; i >= 1; i--)
      tree[i] = min(tree[i << 1], tree[i << 1 | 1]);
  }
  int query(int l, int r) {
    l += TSIZE;
    r += TSIZE;
    int ret = INT_MAX;
    while (l <= r) {
      if (l & 1) ret = min(ret, tree[l++]);
      if (!(r & 1)) ret = min(ret, tree[r--]);
      l >>= 1;
      r >>= 1;
    }
    return ret;
  }
} rmq;
struct lazyprop {
  static constexpr int TSIZE = 1048576;
  int segtree[TSIZE * 2], prop[TSIZE * 2];
  void relax(int nod, int l, int r) {
    if (prop[nod] == 0) return;
    if (l < r) {
      int m = (l + r) >> 1;
      segtree[nod << 1] = prop[nod];
      prop[nod << 1] = prop[nod];
      segtree[nod << 1 | 1] = prop[nod];
      prop[nod << 1 | 1] = prop[nod];
    }
    prop[nod] = 0;
  }
  int query(int nod, int l, int r, int s, int e) {
    if (r < s || e < l) return INT_MAX;
    if (s <= l && r <= e) return segtree[nod];
    relax(nod, l, r);
    int m = (l + r) >> 1;
    return min(query(nod << 1, l, m, s, e),
               query(nod << 1 | 1, m + 1, r, s, e));
  }
  void update(int nod, int l, int r, int s, int e, int val) {
    if (r < s || e < l) return;
    if (s <= l && r <= e) {
      segtree[nod] = val;
      prop[nod] = val;
      return;
    }
    relax(nod, l, r);
    int m = (l + r) >> 1;
    update(nod << 1, l, m, s, e, val);
    update(nod << 1 | 1, m + 1, r, s, e, val);
    segtree[nod] = min(segtree[nod << 1], segtree[nod << 1 | 1]);
  }
} lazy;
int n, k;
int get_raw(int l, int r) {
  int lbkt = l / n;
  int rbkt = r / n;
  if (lbkt == rbkt) {
    return rmq.query(l % n, r % n);
  } else if (lbkt + 1 == rbkt) {
    return min(rmq.query(l % n, n - 1), rmq.query(0, r % n));
  } else {
    return rmq.query(0, n - 1);
  }
}
vector<int> coord;
struct query {
  int type, l, r, x;
} qry[100005];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", &dat[i]);
  rmq.init(n, dat);
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d%d%d", &qry[i].type, &qry[i].l, &qry[i].r);
    --qry[i].l;
    --qry[i].r;
    if (qry[i].type == 1) scanf("%d", &qry[i].x);
    coord.push_back(qry[i].l);
    if (qry[i].l) coord.push_back(qry[i].l - 1);
    coord.push_back(qry[i].l + 1);
    coord.push_back(qry[i].r);
    if (qry[i].r) coord.push_back(qry[i].r - 1);
    coord.push_back(qry[i].r + 1);
  }
  sort(coord.begin(), coord.end());
  coord.erase(unique(coord.begin(), coord.end()), coord.end());
  for (int i = 0; i < coord.size() - 1; i++) {
    lazy.update(1, 0, lazy.TSIZE - 1, i, i,
                get_raw(coord[i], coord[i + 1] - 1));
  }
  for (int i = 0; i < q; i++) {
    int L = lower_bound(coord.begin(), coord.end(), qry[i].l) - coord.begin();
    int R = lower_bound(coord.begin(), coord.end(), qry[i].r) - coord.begin();
    if (qry[i].type == 1) {
      lazy.update(1, 0, lazy.TSIZE - 1, L, R, qry[i].x);
    } else {
      printf("%d\n", lazy.query(1, 0, lazy.TSIZE - 1, L, R));
    }
  }
}

### 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;
int dat[100005];
struct RMQ {
  static constexpr int TSIZE = 131072;
  int tree[TSIZE * 2];
  void init(int n, int *d) {
    memcpy(tree + TSIZE, d, sizeof(int) * n);
    for (int i = TSIZE - 1; i >= 1; i--)
      tree[i] = min(tree[i << 1], tree[i << 1 | 1]);
  }
  int query(int l, int r) {
    l += TSIZE;
    r += TSIZE;
    int ret = INT_MAX;
    while (l <= r) {
      if (l & 1) ret = min(ret, tree[l++]);
      if (!(r & 1)) ret = min(ret, tree[r--]);
      l >>= 1;
      r >>= 1;
    }
    return ret;
  }
} rmq;
struct lazyprop {
  static constexpr int TSIZE = 1048576;
  int segtree[TSIZE * 2], prop[TSIZE * 2];
  void relax(int nod, int l, int r) {
    if (prop[nod] == 0) return;
    if (l < r) {
      int m = (l + r) >> 1;
      segtree[nod << 1] = prop[nod];
      prop[nod << 1] = prop[nod];
      segtree[nod << 1 | 1] = prop[nod];
      prop[nod << 1 | 1] = prop[nod];
    }
    prop[nod] = 0;
  }
  int query(int nod, int l, int r, int s, int e) {
    if (r < s || e < l) return INT_MAX;
    if (s <= l && r <= e) return segtree[nod];
    relax(nod, l, r);
    int m = (l + r) >> 1;
    return min(query(nod << 1, l, m, s, e),
               query(nod << 1 | 1, m + 1, r, s, e));
  }
  void update(int nod, int l, int r, int s, int e, int val) {
    if (r < s || e < l) return;
    if (s <= l && r <= e) {
      segtree[nod] = val;
      prop[nod] = val;
      return;
    }
    relax(nod, l, r);
    int m = (l + r) >> 1;
    update(nod << 1, l, m, s, e, val);
    update(nod << 1 | 1, m + 1, r, s, e, val);
    segtree[nod] = min(segtree[nod << 1], segtree[nod << 1 | 1]);
  }
} lazy;
int n, k;
int get_raw(int l, int r) {
  int lbkt = l / n;
  int rbkt = r / n;
  if (lbkt == rbkt) {
    return rmq.query(l % n, r % n);
  } else if (lbkt + 1 == rbkt) {
    return min(rmq.query(l % n, n - 1), rmq.query(0, r % n));
  } else {
    return rmq.query(0, n - 1);
  }
}
vector<int> coord;
struct query {
  int type, l, r, x;
} qry[100005];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", &dat[i]);
  rmq.init(n, dat);
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d%d%d", &qry[i].type, &qry[i].l, &qry[i].r);
    --qry[i].l;
    --qry[i].r;
    if (qry[i].type == 1) scanf("%d", &qry[i].x);
    coord.push_back(qry[i].l);
    if (qry[i].l) coord.push_back(qry[i].l - 1);
    coord.push_back(qry[i].l + 1);
    coord.push_back(qry[i].r);
    if (qry[i].r) coord.push_back(qry[i].r - 1);
    coord.push_back(qry[i].r + 1);
  }
  sort(coord.begin(), coord.end());
  coord.erase(unique(coord.begin(), coord.end()), coord.end());
  for (int i = 0; i < coord.size() - 1; i++) {
    lazy.update(1, 0, lazy.TSIZE - 1, i, i,
                get_raw(coord[i], coord[i + 1] - 1));
  }
  for (int i = 0; i < q; i++) {
    int L = lower_bound(coord.begin(), coord.end(), qry[i].l) - coord.begin();
    int R = lower_bound(coord.begin(), coord.end(), qry[i].r) - coord.begin();
    if (qry[i].type == 1) {
      lazy.update(1, 0, lazy.TSIZE - 1, L, R, qry[i].x);
    } else {
      printf("%d\n", lazy.query(1, 0, lazy.TSIZE - 1, L, R));
    }
  }
}

```