#include <bits/stdc++.h>
using namespace std;
const int N = 4e5;
int gi() {
  int w = 0;
  bool q = 1;
  char c = getchar();
  while ((c < '0' || c > '9') && c != '-') c = getchar();
  if (c == '-') q = 0, c = getchar();
  while (c >= '0' && c <= '9') w = w * 10 + c - '0', c = getchar();
  return q ? w : -w;
}
int mi[N << 2], tag[N << 2], f[N];
inline void build(int i, int l, int r) {
  if (l == r)
    mi[i] = f[l];
  else {
    int mid = (l + r) >> 1;
    build((i << 1), l, mid);
    build(((i << 1) | 1), mid + 1, r);
    mi[i] = min(mi[(i << 1)], mi[((i << 1) | 1)]);
  }
}
inline void modify(int i, int l, int r, int L, int R, int d) {
  if (L <= l && r <= R)
    tag[i] = mi[i] = d;
  else {
    int mid = (l + r) >> 1;
    if (tag[i])
      tag[(i << 1)] = mi[(i << 1)] = tag[((i << 1) | 1)] = mi[((i << 1) | 1)] =
          tag[i],
                tag[i] = 0;
    if (L <= mid) modify((i << 1), l, mid, L, R, d);
    if (mid < R) modify(((i << 1) | 1), mid + 1, r, L, R, d);
    mi[i] = min(mi[(i << 1)], mi[((i << 1) | 1)]);
  }
}
inline int query(int i, int l, int r, int L, int R) {
  if (tag[i]) return tag[i];
  if (L <= l && r <= R) return mi[i];
  int mid = (l + r) >> 1;
  return min(L <= mid ? query((i << 1), l, mid, L, R) : 1 << 30,
             mid < R ? query(((i << 1) | 1), mid + 1, r, L, R) : 1 << 30);
}
int ST[20][N], Log[N], x[N], p[N];
int op[N], L[N], R[N], to[N];
inline int build(int n) {
  int i, t, mi = 1 << 30, len;
  for (i = 0; i < n; i++) mi = min(mi, ST[0][i] = gi());
  for (t = len = 1; t < 20; t++, len <<= 1)
    for (i = n - (1 << t); i >= 0; i--)
      ST[t][i] = min(ST[t - 1][i], ST[t - 1][i + len]);
  for (i = 1, Log[0] = -1; i <= n; i++) Log[i] = Log[i >> 1] + 1;
  return mi;
}
inline int find(int l, int r) {
  int s = Log[r - l + 1];
  return min(ST[s][l], ST[s][r - (1 << s) + 1]);
}
int main() {
  int n = gi(), Q, i, t, len, l, r, mid;
  gi();
  t = build(n);
  for (i = 1, Q = gi(), len = 0; i <= Q; i++)
    if (op[i] = gi(), L[i] = x[++len] = gi() - 1, R[i] = x[++len] = gi() - 1,
        op[i] == 1)
      to[i] = gi();
  sort(x + 1, x + 1 + len);
  len = unique(x + 1, x + 1 + len) - x - 1;
  for (i = 1, l = len, len = 0; i <= l; i++) {
    if (i > 1 && x[i] != p[len] + 1) {
      p[len + 1] = p[len] + 1;
      if (x[i] - p[++len] >= n)
        f[len] = t;
      else if ((x[i] - 1) / n == p[len] / n)
        f[len] = find(p[len] % n, (x[i] - 1) % n);
      else
        f[len] = min(find(p[len] % n, n - 1), find(0, (x[i] - 1) % n));
    }
    p[++len] = x[i], f[len] = ST[0][x[i] % n];
  }
  build(1, 1, len);
  for (i = 1; i <= Q; i++) {
    for (l = 1, r = len; l != r;
         L[i] <= p[mid = (l + r) >> 1] ? r = mid : l = mid + 1)
      ;
    L[i] = l;
    for (r = len; l != r; R[i] <= p[mid = (l + r) >> 1] ? r = mid : l = mid + 1)
      ;
    R[i] = r;
    if (op[i] == 1)
      modify(1, 1, len, L[i], R[i], to[i]);
    else
      printf("%d\n", query(1, 1, len, L[i], R[i]));
  }
  return 0;
}

### 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;
const int N = 4e5;
int gi() {
  int w = 0;
  bool q = 1;
  char c = getchar();
  while ((c < '0' || c > '9') && c != '-') c = getchar();
  if (c == '-') q = 0, c = getchar();
  while (c >= '0' && c <= '9') w = w * 10 + c - '0', c = getchar();
  return q ? w : -w;
}
int mi[N << 2], tag[N << 2], f[N];
inline void build(int i, int l, int r) {
  if (l == r)
    mi[i] = f[l];
  else {
    int mid = (l + r) >> 1;
    build((i << 1), l, mid);
    build(((i << 1) | 1), mid + 1, r);
    mi[i] = min(mi[(i << 1)], mi[((i << 1) | 1)]);
  }
}
inline void modify(int i, int l, int r, int L, int R, int d) {
  if (L <= l && r <= R)
    tag[i] = mi[i] = d;
  else {
    int mid = (l + r) >> 1;
    if (tag[i])
      tag[(i << 1)] = mi[(i << 1)] = tag[((i << 1) | 1)] = mi[((i << 1) | 1)] =
          tag[i],
                tag[i] = 0;
    if (L <= mid) modify((i << 1), l, mid, L, R, d);
    if (mid < R) modify(((i << 1) | 1), mid + 1, r, L, R, d);
    mi[i] = min(mi[(i << 1)], mi[((i << 1) | 1)]);
  }
}
inline int query(int i, int l, int r, int L, int R) {
  if (tag[i]) return tag[i];
  if (L <= l && r <= R) return mi[i];
  int mid = (l + r) >> 1;
  return min(L <= mid ? query((i << 1), l, mid, L, R) : 1 << 30,
             mid < R ? query(((i << 1) | 1), mid + 1, r, L, R) : 1 << 30);
}
int ST[20][N], Log[N], x[N], p[N];
int op[N], L[N], R[N], to[N];
inline int build(int n) {
  int i, t, mi = 1 << 30, len;
  for (i = 0; i < n; i++) mi = min(mi, ST[0][i] = gi());
  for (t = len = 1; t < 20; t++, len <<= 1)
    for (i = n - (1 << t); i >= 0; i--)
      ST[t][i] = min(ST[t - 1][i], ST[t - 1][i + len]);
  for (i = 1, Log[0] = -1; i <= n; i++) Log[i] = Log[i >> 1] + 1;
  return mi;
}
inline int find(int l, int r) {
  int s = Log[r - l + 1];
  return min(ST[s][l], ST[s][r - (1 << s) + 1]);
}
int main() {
  int n = gi(), Q, i, t, len, l, r, mid;
  gi();
  t = build(n);
  for (i = 1, Q = gi(), len = 0; i <= Q; i++)
    if (op[i] = gi(), L[i] = x[++len] = gi() - 1, R[i] = x[++len] = gi() - 1,
        op[i] == 1)
      to[i] = gi();
  sort(x + 1, x + 1 + len);
  len = unique(x + 1, x + 1 + len) - x - 1;
  for (i = 1, l = len, len = 0; i <= l; i++) {
    if (i > 1 && x[i] != p[len] + 1) {
      p[len + 1] = p[len] + 1;
      if (x[i] - p[++len] >= n)
        f[len] = t;
      else if ((x[i] - 1) / n == p[len] / n)
        f[len] = find(p[len] % n, (x[i] - 1) % n);
      else
        f[len] = min(find(p[len] % n, n - 1), find(0, (x[i] - 1) % n));
    }
    p[++len] = x[i], f[len] = ST[0][x[i] % n];
  }
  build(1, 1, len);
  for (i = 1; i <= Q; i++) {
    for (l = 1, r = len; l != r;
         L[i] <= p[mid = (l + r) >> 1] ? r = mid : l = mid + 1)
      ;
    L[i] = l;
    for (r = len; l != r; R[i] <= p[mid = (l + r) >> 1] ? r = mid : l = mid + 1)
      ;
    R[i] = r;
    if (op[i] == 1)
      modify(1, 1, len, L[i], R[i], to[i]);
    else
      printf("%d\n", query(1, 1, len, L[i], R[i]));
  }
  return 0;
}

```