#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 3;
const int INF = 1e9;
struct Query {
  int op, l, r, x;
} q[MAXN];
int nq;
struct ST {
  vector<int> log;
  vector<vector<int>> f;
  ST(vector<int>& a) {
    int n = a.size();
    log.resize(n + 1);
    log[1] = 0;
    for (int i = 2; i <= n; i++) log[i] = log[i >> 1] + 1;
    f.resize(n);
    for (auto& v : f) v.resize(31);
    for (int i = 0; i < n; i++) f[i][0] = a[i];
    for (int j = 1; j < 31; j++)
      for (int i = 0; i < n; i++)
        f[i][j] = min(f[i][j - 1], f[min(n - 1, i + (1 << (j - 1)))][j - 1]);
  }
  int query(int l, int r) {
    int k = log[r - l + 1];
    assert(0 <= l && l <= r && r < f.size());
    return min(f[l][k], f[r + 1 - (1 << k)][k]);
  }
};
struct SegmentTree {
  struct Node {
    int v, t, x;
  };
  int n;
  vector<Node> node;
  int ql, qr, qx;
  SegmentTree(vector<int>& a) {
    n = a.size();
    node.resize(n << 2);
    for (auto& n : node) n.t = n.v = n.x = 0;
    build(1, n, 1, a);
  }
  inline int left(int i) { return i << 1; }
  inline int right(int i) { return (i << 1) + 1; }
  inline void update(int l, int r, int p, int x) {
    node[p].v = x;
    node[p].t = 1;
    node[p].x = x;
  }
  inline void pushdown(int l, int r, int p, int m, int lc, int rc) {
    if (node[p].t) {
      node[p].t = 0;
      update(l, m, lc, node[p].x);
      update(m + 1, r, rc, node[p].x);
    }
  }
  void build(int l, int r, int p, vector<int>& a) {
    if (l == r)
      node[p].v = a[l - 1];
    else {
      int m = (l + r) / 2, lc = left(p), rc = right(p);
      build(l, m, lc, a), build(m + 1, r, rc, a);
      node[p].v = min(node[lc].v, node[rc].v);
    }
  }
  void modify(int l, int r, int p) {
    if (ql <= l && r <= qr)
      update(l, r, p, qx);
    else if (ql <= r && qr >= l) {
      int m = (l + r) / 2, lc = left(p), rc = right(p);
      pushdown(l, r, p, m, lc, rc);
      modify(l, m, lc), modify(m + 1, r, rc);
      node[p].v = min(node[lc].v, node[rc].v);
    }
  }
  int query(int l, int r, int p) {
    if (ql <= l && r <= qr)
      return node[p].v;
    else if (ql <= r && qr >= l) {
      int m = (l + r) / 2, lc = left(p), rc = right(p);
      pushdown(l, r, p, m, lc, rc);
      return min(query(l, m, lc), query(m + 1, r, rc));
    }
    return INF;
  }
  void set(int l, int r, int x) {
    ql = l + 1, qr = r + 1, qx = x;
    modify(1, n, 1);
  }
  int query_min(int l, int r) {
    ql = l + 1, qr = r + 1;
    return query(1, n, 1);
  }
};
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  vector<int> a(n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  scanf("%d", &nq);
  vector<int> idx;
  idx.reserve(2 * nq);
  for (int i = 0; i < nq; i++) {
    scanf("%d%d%d", &q[i].op, &q[i].l, &q[i].r);
    q[i].l--, q[i].r--;
    if (q[i].op == 1) scanf("%d", &q[i].x);
    idx.push_back(q[i].l);
    idx.push_back(q[i].r);
  }
  sort(idx.begin(), idx.end());
  idx.resize(unique(idx.begin(), idx.end()) - idx.begin());
  ST st(a);
  vector<int> mins;
  map<int, int> imap;
  int prei = idx[0] - 1;
  for (auto& i : idx) {
    if (i != prei + 1) {
      int l = prei + 1, r = i - 1;
      int ml = l % n, mr = r % n;
      int x;
      if (r - l + 1 >= n)
        x = st.query(0, n - 1);
      else if (ml <= mr)
        x = st.query(ml, mr);
      else
        x = min(st.query(0, mr), st.query(ml, n - 1));
      mins.push_back(x);
    }
    mins.push_back(a[i % n]);
    imap[i] = mins.size() - 1;
    prei = i;
  }
  SegmentTree smt(mins);
  for (int i = 0; i < nq; i++) {
    int l = imap[q[i].l], r = imap[q[i].r];
    if (q[i].op == 1)
      smt.set(l, r, q[i].x);
    else
      printf("%d\n", smt.query_min(l, r));
  }
  return 0;
}

### Prompt

Create a solution in cpp for 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 MAXN = 1e5 + 3;
const int INF = 1e9;
struct Query {
  int op, l, r, x;
} q[MAXN];
int nq;
struct ST {
  vector<int> log;
  vector<vector<int>> f;
  ST(vector<int>& a) {
    int n = a.size();
    log.resize(n + 1);
    log[1] = 0;
    for (int i = 2; i <= n; i++) log[i] = log[i >> 1] + 1;
    f.resize(n);
    for (auto& v : f) v.resize(31);
    for (int i = 0; i < n; i++) f[i][0] = a[i];
    for (int j = 1; j < 31; j++)
      for (int i = 0; i < n; i++)
        f[i][j] = min(f[i][j - 1], f[min(n - 1, i + (1 << (j - 1)))][j - 1]);
  }
  int query(int l, int r) {
    int k = log[r - l + 1];
    assert(0 <= l && l <= r && r < f.size());
    return min(f[l][k], f[r + 1 - (1 << k)][k]);
  }
};
struct SegmentTree {
  struct Node {
    int v, t, x;
  };
  int n;
  vector<Node> node;
  int ql, qr, qx;
  SegmentTree(vector<int>& a) {
    n = a.size();
    node.resize(n << 2);
    for (auto& n : node) n.t = n.v = n.x = 0;
    build(1, n, 1, a);
  }
  inline int left(int i) { return i << 1; }
  inline int right(int i) { return (i << 1) + 1; }
  inline void update(int l, int r, int p, int x) {
    node[p].v = x;
    node[p].t = 1;
    node[p].x = x;
  }
  inline void pushdown(int l, int r, int p, int m, int lc, int rc) {
    if (node[p].t) {
      node[p].t = 0;
      update(l, m, lc, node[p].x);
      update(m + 1, r, rc, node[p].x);
    }
  }
  void build(int l, int r, int p, vector<int>& a) {
    if (l == r)
      node[p].v = a[l - 1];
    else {
      int m = (l + r) / 2, lc = left(p), rc = right(p);
      build(l, m, lc, a), build(m + 1, r, rc, a);
      node[p].v = min(node[lc].v, node[rc].v);
    }
  }
  void modify(int l, int r, int p) {
    if (ql <= l && r <= qr)
      update(l, r, p, qx);
    else if (ql <= r && qr >= l) {
      int m = (l + r) / 2, lc = left(p), rc = right(p);
      pushdown(l, r, p, m, lc, rc);
      modify(l, m, lc), modify(m + 1, r, rc);
      node[p].v = min(node[lc].v, node[rc].v);
    }
  }
  int query(int l, int r, int p) {
    if (ql <= l && r <= qr)
      return node[p].v;
    else if (ql <= r && qr >= l) {
      int m = (l + r) / 2, lc = left(p), rc = right(p);
      pushdown(l, r, p, m, lc, rc);
      return min(query(l, m, lc), query(m + 1, r, rc));
    }
    return INF;
  }
  void set(int l, int r, int x) {
    ql = l + 1, qr = r + 1, qx = x;
    modify(1, n, 1);
  }
  int query_min(int l, int r) {
    ql = l + 1, qr = r + 1;
    return query(1, n, 1);
  }
};
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  vector<int> a(n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  scanf("%d", &nq);
  vector<int> idx;
  idx.reserve(2 * nq);
  for (int i = 0; i < nq; i++) {
    scanf("%d%d%d", &q[i].op, &q[i].l, &q[i].r);
    q[i].l--, q[i].r--;
    if (q[i].op == 1) scanf("%d", &q[i].x);
    idx.push_back(q[i].l);
    idx.push_back(q[i].r);
  }
  sort(idx.begin(), idx.end());
  idx.resize(unique(idx.begin(), idx.end()) - idx.begin());
  ST st(a);
  vector<int> mins;
  map<int, int> imap;
  int prei = idx[0] - 1;
  for (auto& i : idx) {
    if (i != prei + 1) {
      int l = prei + 1, r = i - 1;
      int ml = l % n, mr = r % n;
      int x;
      if (r - l + 1 >= n)
        x = st.query(0, n - 1);
      else if (ml <= mr)
        x = st.query(ml, mr);
      else
        x = min(st.query(0, mr), st.query(ml, n - 1));
      mins.push_back(x);
    }
    mins.push_back(a[i % n]);
    imap[i] = mins.size() - 1;
    prei = i;
  }
  SegmentTree smt(mins);
  for (int i = 0; i < nq; i++) {
    int l = imap[q[i].l], r = imap[q[i].r];
    if (q[i].op == 1)
      smt.set(l, r, q[i].x);
    else
      printf("%d\n", smt.query_min(l, r));
  }
  return 0;
}

```