#include <bits/stdc++.h>
using namespace std;
int n, k, q, all, tot;
int sum[1000010], minx[1000010];
int a[1000010], b[1000010], pre[1000010];
int base[1000010], lazy[1000010];
struct question {
  int opt, l, r, val;
} qu[1000010];
int read() {
  int s = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    s = (s << 1) + (s << 3) + ch - '0';
    ch = getchar();
  }
  return s * w;
}
namespace Seg1 {
void pushup(int x) { sum[x] = min(sum[x << 1], sum[x << 1 | 1]); }
void build(int x, int l, int r) {
  if (l == r) {
    sum[x] = a[l];
    return;
  }
  int mid = l + r >> 1;
  build(x << 1, l, mid);
  build(x << 1 | 1, mid + 1, r);
  pushup(x);
}
int querymin(int x, int l, int r, int L, int R) {
  if (L <= l && R >= r) return sum[x];
  int mid = l + r >> 1;
  int ans = 0x3f3f3f3f;
  if (L <= mid) ans = min(ans, querymin(x << 1, l, mid, L, R));
  if (R >= mid + 1) ans = min(ans, querymin(x << 1 | 1, mid + 1, r, L, R));
  return ans;
}
}  // namespace Seg1
namespace Seg2 {
void pushup(int x) { minx[x] = min(minx[x << 1], minx[x << 1 | 1]); }
void pushdown(int x) {
  if (lazy[x] == -1) return;
  minx[x << 1] = minx[x << 1 | 1] = lazy[x];
  lazy[x << 1] = lazy[x << 1 | 1] = lazy[x];
  lazy[x] = -1;
}
void build(int x, int l, int r) {
  if (l == r) {
    minx[x] = b[l];
    return;
  }
  int mid = l + r >> 1;
  build(x << 1, l, mid);
  build(x << 1 | 1, mid + 1, r);
  pushup(x);
}
void update(int x, int l, int r, int L, int R, int val) {
  if (L <= l && R >= r) {
    lazy[x] = minx[x] = val;
    return;
  }
  int mid = l + r >> 1;
  pushdown(x);
  if (L <= mid) update(x << 1, l, mid, L, R, val);
  if (R >= mid + 1) update(x << 1 | 1, mid + 1, r, L, R, val);
  pushup(x);
}
int querymin(int x, int l, int r, int L, int R) {
  if (L <= l && R >= r) return minx[x];
  int mid = l + r >> 1;
  int ans = 0x3f3f3f3f;
  pushdown(x);
  if (L <= mid) ans = min(ans, querymin(x << 1, l, mid, L, R));
  if (R >= mid + 1) ans = min(ans, querymin(x << 1 | 1, mid + 1, r, L, R));
  return ans;
}
}  // namespace Seg2
int main() {
  n = read();
  k = read();
  memset(lazy, -1, sizeof lazy);
  for (int i = 1; i <= n; i++) a[i] = read();
  q = read();
  for (int i = 1, opt; i <= q; i++) {
    qu[i].opt = read();
    qu[i].l = read();
    qu[i].r = read();
    base[++all] = qu[i].l;
    base[++all] = qu[i].r;
    if (qu[i].opt == 1) qu[i].val = read();
  }
  Seg1::build(1, 1, n);
  sort(base + 1, base + all + 1);
  int Now = unique(base + 1, base + all + 1) - base - 1;
  for (int i = 1; i <= q; i++) {
    qu[i].l = lower_bound(base + 1, base + Now + 1, qu[i].l) - base;
    qu[i].r = lower_bound(base + 1, base + Now + 1, qu[i].r) - base;
  }
  for (int i = 1; i < Now; i++) {
    if (!(base[i] % n))
      b[++tot] = a[n];
    else
      b[++tot] = a[base[i] % n];
    pre[i] = tot;
    if (base[i + 1] - 1 - (base[i] + 1) >= n)
      b[++tot] = sum[1];
    else if (base[i + 1] - base[i] > 1) {
      int l = (base[i] + 1) % n;
      int r = (base[i + 1] - 1) % n;
      l = (!l) ? n : l;
      r = (!r) ? n : r;
      if (l <= r)
        b[++tot] = Seg1::querymin(1, 1, n, l, r);
      else
        b[++tot] =
            min(Seg1::querymin(1, 1, n, 1, r), Seg1::querymin(1, 1, n, l, n));
    }
  }
  if (!(base[Now] % n))
    b[++tot] = a[n];
  else
    b[++tot] = a[base[Now] % n];
  pre[Now] = tot;
  Seg2::build(1, 1, tot);
  for (int i = 1; i <= q; i++) {
    qu[i].l = pre[qu[i].l], qu[i].r = pre[qu[i].r];
    if (qu[i].opt == 1)
      Seg2::update(1, 1, tot, qu[i].l, qu[i].r, qu[i].val);
    else
      printf("%d\n", Seg2::querymin(1, 1, tot, qu[i].l, qu[i].r));
  }
  return 0;
}

### Prompt

Please create a solution in cpp 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 n, k, q, all, tot;
int sum[1000010], minx[1000010];
int a[1000010], b[1000010], pre[1000010];
int base[1000010], lazy[1000010];
struct question {
  int opt, l, r, val;
} qu[1000010];
int read() {
  int s = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    s = (s << 1) + (s << 3) + ch - '0';
    ch = getchar();
  }
  return s * w;
}
namespace Seg1 {
void pushup(int x) { sum[x] = min(sum[x << 1], sum[x << 1 | 1]); }
void build(int x, int l, int r) {
  if (l == r) {
    sum[x] = a[l];
    return;
  }
  int mid = l + r >> 1;
  build(x << 1, l, mid);
  build(x << 1 | 1, mid + 1, r);
  pushup(x);
}
int querymin(int x, int l, int r, int L, int R) {
  if (L <= l && R >= r) return sum[x];
  int mid = l + r >> 1;
  int ans = 0x3f3f3f3f;
  if (L <= mid) ans = min(ans, querymin(x << 1, l, mid, L, R));
  if (R >= mid + 1) ans = min(ans, querymin(x << 1 | 1, mid + 1, r, L, R));
  return ans;
}
}  // namespace Seg1
namespace Seg2 {
void pushup(int x) { minx[x] = min(minx[x << 1], minx[x << 1 | 1]); }
void pushdown(int x) {
  if (lazy[x] == -1) return;
  minx[x << 1] = minx[x << 1 | 1] = lazy[x];
  lazy[x << 1] = lazy[x << 1 | 1] = lazy[x];
  lazy[x] = -1;
}
void build(int x, int l, int r) {
  if (l == r) {
    minx[x] = b[l];
    return;
  }
  int mid = l + r >> 1;
  build(x << 1, l, mid);
  build(x << 1 | 1, mid + 1, r);
  pushup(x);
}
void update(int x, int l, int r, int L, int R, int val) {
  if (L <= l && R >= r) {
    lazy[x] = minx[x] = val;
    return;
  }
  int mid = l + r >> 1;
  pushdown(x);
  if (L <= mid) update(x << 1, l, mid, L, R, val);
  if (R >= mid + 1) update(x << 1 | 1, mid + 1, r, L, R, val);
  pushup(x);
}
int querymin(int x, int l, int r, int L, int R) {
  if (L <= l && R >= r) return minx[x];
  int mid = l + r >> 1;
  int ans = 0x3f3f3f3f;
  pushdown(x);
  if (L <= mid) ans = min(ans, querymin(x << 1, l, mid, L, R));
  if (R >= mid + 1) ans = min(ans, querymin(x << 1 | 1, mid + 1, r, L, R));
  return ans;
}
}  // namespace Seg2
int main() {
  n = read();
  k = read();
  memset(lazy, -1, sizeof lazy);
  for (int i = 1; i <= n; i++) a[i] = read();
  q = read();
  for (int i = 1, opt; i <= q; i++) {
    qu[i].opt = read();
    qu[i].l = read();
    qu[i].r = read();
    base[++all] = qu[i].l;
    base[++all] = qu[i].r;
    if (qu[i].opt == 1) qu[i].val = read();
  }
  Seg1::build(1, 1, n);
  sort(base + 1, base + all + 1);
  int Now = unique(base + 1, base + all + 1) - base - 1;
  for (int i = 1; i <= q; i++) {
    qu[i].l = lower_bound(base + 1, base + Now + 1, qu[i].l) - base;
    qu[i].r = lower_bound(base + 1, base + Now + 1, qu[i].r) - base;
  }
  for (int i = 1; i < Now; i++) {
    if (!(base[i] % n))
      b[++tot] = a[n];
    else
      b[++tot] = a[base[i] % n];
    pre[i] = tot;
    if (base[i + 1] - 1 - (base[i] + 1) >= n)
      b[++tot] = sum[1];
    else if (base[i + 1] - base[i] > 1) {
      int l = (base[i] + 1) % n;
      int r = (base[i + 1] - 1) % n;
      l = (!l) ? n : l;
      r = (!r) ? n : r;
      if (l <= r)
        b[++tot] = Seg1::querymin(1, 1, n, l, r);
      else
        b[++tot] =
            min(Seg1::querymin(1, 1, n, 1, r), Seg1::querymin(1, 1, n, l, n));
    }
  }
  if (!(base[Now] % n))
    b[++tot] = a[n];
  else
    b[++tot] = a[base[Now] % n];
  pre[Now] = tot;
  Seg2::build(1, 1, tot);
  for (int i = 1; i <= q; i++) {
    qu[i].l = pre[qu[i].l], qu[i].r = pre[qu[i].r];
    if (qu[i].opt == 1)
      Seg2::update(1, 1, tot, qu[i].l, qu[i].r, qu[i].val);
    else
      printf("%d\n", Seg2::querymin(1, 1, tot, qu[i].l, qu[i].r));
  }
  return 0;
}

```