#include <bits/stdc++.h>
using namespace std;
const int NMAX = 1e5 + 5;
const int LMAX = 1e1 + 7;
const int VMAX = 1e9 + 5;
int rmq[LMAX][NMAX], pwr[NMAX];
struct T {
  int mnm, lzy;
  T *l, *r;
  T(int _mnm = VMAX, int _lzy = -1, T *_l = NULL, T *_r = NULL)
      : mnm(_mnm), lzy(_lzy), l(_l), r(_r) {}
} * sgt;
inline int getrmq(int l, int r) {
  int p = pwr[r - l + 1];
  return min(rmq[p][l], rmq[p][r - (1 << p) + 1]);
}
inline int getval(int l, int r, int n) {
  if (l / n == r / n) return getrmq(l % n, r % n);
  if (l / n + 1 == r / n) return min(getrmq(l % n, n - 1), getrmq(0, r % n));
  return getrmq(0, n - 1);
}
inline int getmin(T *n) {
  if (n == NULL) return VMAX;
  return n->mnm;
}
inline void updatel(T *n, int l, int r) {
  if (n->lzy != -1) {
    if (l != r) {
      if (n->l == NULL) n->l = new T(n->lzy, n->lzy);
      if (n->r == NULL) n->r = new T(n->lzy, n->lzy);
      n->l->mnm = n->l->lzy = n->lzy;
      n->r->mnm = n->r->lzy = n->lzy;
    }
    n->mnm = n->lzy;
    n->lzy = -1;
  }
  return;
}
void update(T *n, int l, int r, int st, int en, int x, int p) {
  if (r < st || en < l) return;
  if (st <= l && r <= en) {
    n->mnm = n->lzy = x;
    return;
  }
  updatel(n, l, r);
  int m = (l + r) >> 1;
  if (n->l == NULL) n->l = new T(getval(l, m, p));
  if (n->r == NULL) n->r = new T(getval(m + 1, r, p));
  if (st <= m) update(n->l, l, m, st, en, x, p);
  if (en > m) update(n->r, m + 1, r, st, en, x, p);
  n->mnm = min(getmin(n->l), getmin(n->r));
  return;
}
int query(T *n, int l, int r, int st, int en, int p) {
  if (r < st || en < l) return VMAX;
  if (st <= l && r <= en) return n->mnm;
  updatel(n, l, r);
  int m = (l + r) >> 1;
  int ans = VMAX;
  if (st <= m) {
    if (n->l == NULL) n->l = new T(getval(l, m, p));
    ans = min(ans, query(n->l, l, m, st, en, p));
  }
  if (en > m) {
    if (n->r == NULL) n->r = new T(getval(m + 1, r, p));
    ans = min(ans, query(n->r, m + 1, r, st, en, p));
  }
  return ans;
}
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  int n, k;
  cin >> n >> k;
  for (int i = 2; i <= n; i++) pwr[i] = pwr[i >> 1] + 1;
  for (int i = 0; i < n; i++) cin >> rmq[0][i];
  for (int k = 1; (1 << k) <= n; k++)
    for (int i = 0; i + (1 << k) <= n; i++)
      rmq[k][i] = min(rmq[k - 1][i], rmq[k - 1][i + (1 << (k - 1))]);
  int q;
  cin >> q;
  sgt = new T(getval(0, n * k - 1, n));
  while (q--) {
    int t;
    cin >> t;
    if (t == 1) {
      int l, r, x;
      cin >> l >> r >> x;
      update(sgt, 0, n * k - 1, --l, --r, x, n);
    } else {
      int l, r;
      cin >> l >> r;
      cout << query(sgt, 0, n * k - 1, --l, --r, n) << "\n";
    }
  }
  return 0;
}

### Prompt

Develop a solution in Cpp to the problem described below:

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 NMAX = 1e5 + 5;
const int LMAX = 1e1 + 7;
const int VMAX = 1e9 + 5;
int rmq[LMAX][NMAX], pwr[NMAX];
struct T {
  int mnm, lzy;
  T *l, *r;
  T(int _mnm = VMAX, int _lzy = -1, T *_l = NULL, T *_r = NULL)
      : mnm(_mnm), lzy(_lzy), l(_l), r(_r) {}
} * sgt;
inline int getrmq(int l, int r) {
  int p = pwr[r - l + 1];
  return min(rmq[p][l], rmq[p][r - (1 << p) + 1]);
}
inline int getval(int l, int r, int n) {
  if (l / n == r / n) return getrmq(l % n, r % n);
  if (l / n + 1 == r / n) return min(getrmq(l % n, n - 1), getrmq(0, r % n));
  return getrmq(0, n - 1);
}
inline int getmin(T *n) {
  if (n == NULL) return VMAX;
  return n->mnm;
}
inline void updatel(T *n, int l, int r) {
  if (n->lzy != -1) {
    if (l != r) {
      if (n->l == NULL) n->l = new T(n->lzy, n->lzy);
      if (n->r == NULL) n->r = new T(n->lzy, n->lzy);
      n->l->mnm = n->l->lzy = n->lzy;
      n->r->mnm = n->r->lzy = n->lzy;
    }
    n->mnm = n->lzy;
    n->lzy = -1;
  }
  return;
}
void update(T *n, int l, int r, int st, int en, int x, int p) {
  if (r < st || en < l) return;
  if (st <= l && r <= en) {
    n->mnm = n->lzy = x;
    return;
  }
  updatel(n, l, r);
  int m = (l + r) >> 1;
  if (n->l == NULL) n->l = new T(getval(l, m, p));
  if (n->r == NULL) n->r = new T(getval(m + 1, r, p));
  if (st <= m) update(n->l, l, m, st, en, x, p);
  if (en > m) update(n->r, m + 1, r, st, en, x, p);
  n->mnm = min(getmin(n->l), getmin(n->r));
  return;
}
int query(T *n, int l, int r, int st, int en, int p) {
  if (r < st || en < l) return VMAX;
  if (st <= l && r <= en) return n->mnm;
  updatel(n, l, r);
  int m = (l + r) >> 1;
  int ans = VMAX;
  if (st <= m) {
    if (n->l == NULL) n->l = new T(getval(l, m, p));
    ans = min(ans, query(n->l, l, m, st, en, p));
  }
  if (en > m) {
    if (n->r == NULL) n->r = new T(getval(m + 1, r, p));
    ans = min(ans, query(n->r, m + 1, r, st, en, p));
  }
  return ans;
}
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  int n, k;
  cin >> n >> k;
  for (int i = 2; i <= n; i++) pwr[i] = pwr[i >> 1] + 1;
  for (int i = 0; i < n; i++) cin >> rmq[0][i];
  for (int k = 1; (1 << k) <= n; k++)
    for (int i = 0; i + (1 << k) <= n; i++)
      rmq[k][i] = min(rmq[k - 1][i], rmq[k - 1][i + (1 << (k - 1))]);
  int q;
  cin >> q;
  sgt = new T(getval(0, n * k - 1, n));
  while (q--) {
    int t;
    cin >> t;
    if (t == 1) {
      int l, r, x;
      cin >> l >> r >> x;
      update(sgt, 0, n * k - 1, --l, --r, x, n);
    } else {
      int l, r;
      cin >> l >> r;
      cout << query(sgt, 0, n * k - 1, --l, --r, n) << "\n";
    }
  }
  return 0;
}

```