#include <bits/stdc++.h>
using namespace std;
int n, k, m;
int b[100005];
int minn[200005][20];
void rmq_init() {
  for (int i = 1; i <= n; i++) {
    minn[i][0] = b[i];
  }
  int k = floor(log((double)n) / log(2.0));
  for (int j = 1; j <= k; j++) {
    for (int i = n; i >= 1; i--) {
      if (i + (1 << (j - 1)) <= n) {
        minn[i][j] = min(minn[i][j - 1], minn[i + (1 << (j - 1))][j - 1]);
      }
    }
  }
}
int rmq(int i, int j) {
  int k = floor(log(j - i + 1) / log(2.0));
  return min(minn[i][k], minn[j - (1 << k) + 1][k]);
}
struct qq {
  int id;
  int x, y, z;
} q[100005];
int a[200005];
int p[200005];
int mm[200005 << 2];
int lazy[200005 << 2];
int cnt = 0;
void pushup(int rt) { mm[rt] = min(mm[rt << 1], mm[rt << 1 | 1]); }
void pushdown(int rt) {
  if (lazy[rt]) {
    mm[rt << 1] = lazy[rt];
    mm[rt << 1 | 1] = lazy[rt];
    lazy[rt << 1] = lazy[rt];
    lazy[rt << 1 | 1] = lazy[rt];
    lazy[rt] = 0;
  }
}
void build(int rt, int l, int r) {
  if (l == r) {
    mm[rt] = p[l];
    return;
  }
  int mid = (l + r) / 2;
  build(rt << 1, l, mid);
  build(rt << 1 | 1, mid + 1, r);
  pushup(rt);
}
void update(int rt, int l, int r, int L, int R, int num) {
  if (L <= l && r <= R) {
    mm[rt] = num;
    lazy[rt] = num;
    return;
  }
  pushdown(rt);
  int mid = (l + r) / 2;
  if (L <= mid) update(rt << 1, l, mid, L, R, num);
  if (R >= mid + 1) update(rt << 1 | 1, mid + 1, r, L, R, num);
  pushup(rt);
}
int query(int rt, int l, int r, int L, int R) {
  if (L <= l && r <= R) {
    return mm[rt];
  }
  pushdown(rt);
  int ret = 1e9;
  int mid = (l + r) / 2;
  if (L <= mid) ret = min(ret, query(rt << 1, l, mid, L, R));
  if (R >= mid + 1) ret = min(ret, query(rt << 1 | 1, mid + 1, r, L, R));
  return ret;
}
void init() {
  for (int i = 1; i < cnt; i++) {
    int L = a[i];
    int R = a[i + 1] - 1;
    if (R - L + 1 >= n) {
      p[i] = rmq(1, n);
    } else {
      int id1 = (L - 1) / n + 1;
      int id2 = (R - 1) / n + 1;
      if (id1 != id2) {
        p[i] = min(rmq(L - (id1 - 1) * n, n), rmq(1, R - n * id1));
      } else if (id1 == id2) {
        p[i] = rmq(L - (id1 - 1) * n, R - (id1 - 1) * n);
      }
    }
  }
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
  }
  rmq_init();
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d", &q[i].id);
    if (q[i].id == 1)
      scanf("%d%d%d", &q[i].x, &q[i].y, &q[i].z);
    else
      scanf("%d%d", &q[i].x, &q[i].y);
    q[i].y++;
    a[++cnt] = q[i].x;
    a[++cnt] = q[i].y;
  }
  sort(a + 1, a + cnt + 1);
  cnt = unique(a + 1, a + cnt + 1) - a - 1;
  init();
  build(1, 1, cnt - 1);
  for (int i = 1; i <= m; i++) {
    if (q[i].id == 1) {
      int L = lower_bound(a + 1, a + cnt + 1, q[i].x) - a;
      int R = lower_bound(a + 1, a + cnt + 1, q[i].y) - a;
      update(1, 1, cnt - 1, L, R - 1, q[i].z);
    } else {
      int L = lower_bound(a + 1, a + cnt + 1, q[i].x) - a;
      int R = lower_bound(a + 1, a + cnt + 1, q[i].y) - a;
      int ans = query(1, 1, cnt - 1, L, R - 1);
      cout << ans << endl;
    }
  }
  return 0;
}

### Prompt

In CPP, your task is to solve 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, m;
int b[100005];
int minn[200005][20];
void rmq_init() {
  for (int i = 1; i <= n; i++) {
    minn[i][0] = b[i];
  }
  int k = floor(log((double)n) / log(2.0));
  for (int j = 1; j <= k; j++) {
    for (int i = n; i >= 1; i--) {
      if (i + (1 << (j - 1)) <= n) {
        minn[i][j] = min(minn[i][j - 1], minn[i + (1 << (j - 1))][j - 1]);
      }
    }
  }
}
int rmq(int i, int j) {
  int k = floor(log(j - i + 1) / log(2.0));
  return min(minn[i][k], minn[j - (1 << k) + 1][k]);
}
struct qq {
  int id;
  int x, y, z;
} q[100005];
int a[200005];
int p[200005];
int mm[200005 << 2];
int lazy[200005 << 2];
int cnt = 0;
void pushup(int rt) { mm[rt] = min(mm[rt << 1], mm[rt << 1 | 1]); }
void pushdown(int rt) {
  if (lazy[rt]) {
    mm[rt << 1] = lazy[rt];
    mm[rt << 1 | 1] = lazy[rt];
    lazy[rt << 1] = lazy[rt];
    lazy[rt << 1 | 1] = lazy[rt];
    lazy[rt] = 0;
  }
}
void build(int rt, int l, int r) {
  if (l == r) {
    mm[rt] = p[l];
    return;
  }
  int mid = (l + r) / 2;
  build(rt << 1, l, mid);
  build(rt << 1 | 1, mid + 1, r);
  pushup(rt);
}
void update(int rt, int l, int r, int L, int R, int num) {
  if (L <= l && r <= R) {
    mm[rt] = num;
    lazy[rt] = num;
    return;
  }
  pushdown(rt);
  int mid = (l + r) / 2;
  if (L <= mid) update(rt << 1, l, mid, L, R, num);
  if (R >= mid + 1) update(rt << 1 | 1, mid + 1, r, L, R, num);
  pushup(rt);
}
int query(int rt, int l, int r, int L, int R) {
  if (L <= l && r <= R) {
    return mm[rt];
  }
  pushdown(rt);
  int ret = 1e9;
  int mid = (l + r) / 2;
  if (L <= mid) ret = min(ret, query(rt << 1, l, mid, L, R));
  if (R >= mid + 1) ret = min(ret, query(rt << 1 | 1, mid + 1, r, L, R));
  return ret;
}
void init() {
  for (int i = 1; i < cnt; i++) {
    int L = a[i];
    int R = a[i + 1] - 1;
    if (R - L + 1 >= n) {
      p[i] = rmq(1, n);
    } else {
      int id1 = (L - 1) / n + 1;
      int id2 = (R - 1) / n + 1;
      if (id1 != id2) {
        p[i] = min(rmq(L - (id1 - 1) * n, n), rmq(1, R - n * id1));
      } else if (id1 == id2) {
        p[i] = rmq(L - (id1 - 1) * n, R - (id1 - 1) * n);
      }
    }
  }
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
  }
  rmq_init();
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d", &q[i].id);
    if (q[i].id == 1)
      scanf("%d%d%d", &q[i].x, &q[i].y, &q[i].z);
    else
      scanf("%d%d", &q[i].x, &q[i].y);
    q[i].y++;
    a[++cnt] = q[i].x;
    a[++cnt] = q[i].y;
  }
  sort(a + 1, a + cnt + 1);
  cnt = unique(a + 1, a + cnt + 1) - a - 1;
  init();
  build(1, 1, cnt - 1);
  for (int i = 1; i <= m; i++) {
    if (q[i].id == 1) {
      int L = lower_bound(a + 1, a + cnt + 1, q[i].x) - a;
      int R = lower_bound(a + 1, a + cnt + 1, q[i].y) - a;
      update(1, 1, cnt - 1, L, R - 1, q[i].z);
    } else {
      int L = lower_bound(a + 1, a + cnt + 1, q[i].x) - a;
      int R = lower_bound(a + 1, a + cnt + 1, q[i].y) - a;
      int ans = query(1, 1, cnt - 1, L, R - 1);
      cout << ans << endl;
    }
  }
  return 0;
}

```