#include <bits/stdc++.h>
using namespace std;
const int N = 100050;
int n, k, q, op, xx, b[N], f[N][20], lson[N << 7], rson[N << 7], root, cnt;
int lazy[N << 7], ans[N << 7], base[N];
int RMQ(int x, int y) {
  int t = base[y - x + 1];
  return min(f[x][t], f[y - (1 << t) + 1][t]);
}
int qry(int l, int r) {
  if (r - l >= n)
    return RMQ(1, n);
  else {
    l = (l - 1) % n + 1, r = (r - 1) % n + 1;
    if (l > r)
      return min(RMQ(1, r), RMQ(l, n));
    else
      return RMQ(l, r);
  }
}
void push_down(int pos) {
  if (!lson[pos]) lson[pos] = ++cnt;
  lazy[lson[pos]] = lazy[pos];
  if (!rson[pos]) rson[pos] = ++cnt;
  lazy[rson[pos]] = lazy[pos];
}
void insert(int l, int r, int &pos, int L, int R, int wei) {
  if (!pos) pos = ++cnt;
  if (lazy[pos] && ~lazy[pos]) {
    ans[pos] = lazy[pos];
    push_down(pos);
    lazy[pos] = -1;
  }
  if (l >= L && r <= R) {
    ans[pos] = lazy[pos] = xx;
    return;
  }
  int mid = (l + r) >> 1;
  if (mid < L)
    insert(mid + 1, r, rson[pos], L, R, wei);
  else if (mid >= R)
    insert(l, mid, lson[pos], L, R, wei);
  else
    insert(l, mid, lson[pos], L, R, wei),
        insert(mid + 1, r, rson[pos], L, R, wei);
  int temp = 0x3f3f3f3f;
  if (lson[pos]) {
    if (!lazy[lson[pos]])
      temp = qry(l, mid);
    else if (lazy[lson[pos]] == -1)
      temp = ans[lson[pos]];
    else
      temp = lazy[lson[pos]];
  } else
    temp = qry(l, mid);
  if (lazy[rson[pos]]) {
    if (!lazy[rson[pos]])
      temp = min(temp, qry(mid + 1, r));
    else if (lazy[rson[pos]] == -1)
      temp = min(temp, ans[rson[pos]]);
    else
      temp = min(temp, lazy[rson[pos]]);
  } else
    temp = min(temp, qry(mid + 1, r));
  ans[pos] = temp, lazy[pos] = -1;
}
int query(int l, int r, int pos, int L, int R) {
  if (l == L && r == R) {
    if (lazy[pos] == -1)
      return ans[pos];
    else if (!lazy[pos])
      return qry(l, r);
    else
      return lazy[pos];
  }
  if (!pos) return qry(L, R);
  if (lazy[pos] && ~lazy[pos]) return lazy[pos];
  int mid = (l + r) >> 1;
  if (mid < L)
    return query(mid + 1, r, rson[pos], L, R);
  else if (mid >= R)
    return query(l, mid, lson[pos], L, R);
  else
    return min(query(l, mid, lson[pos], L, mid),
               query(mid + 1, r, rson[pos], mid + 1, R));
}
void DFS(int l, int r, int pos) {
  printf("l=%d r=%d pos=%d lazy[pos]=%d ans[pos]=%d\n", l, r, pos, lazy[pos],
         ans[pos]);
  int mid = (l + r) >> 1;
  if (lson[pos]) DFS(l, mid, lson[pos]);
  if (rson[pos]) DFS(mid + 1, r, rson[pos]);
}
int main() {
  scanf("%d%d", &n, &k);
  base[0] = -1;
  for (int i = 1; i <= n; i++)
    scanf("%d", &b[i]), f[i][0] = b[i], base[i] = base[i >> 1] + 1;
  for (int j = 1; j <= 19; j++)
    for (int i = 1; i + (1 << (j - 1)) <= n; i++)
      f[i][j] = min(f[i][j - 1], f[i + (1 << (j - 1))][j - 1]);
  scanf("%d", &q);
  while (q--) {
    int l, r;
    scanf("%d%d%d", &op, &l, &r);
    if (op == 1) {
      scanf("%d", &xx);
      insert(1, n * k, root, l, r, xx);
    } else {
      printf("%d\n", query(1, n * k, root, l, r));
    }
  }
}

### Prompt

Your challenge is to write 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 = 100050;
int n, k, q, op, xx, b[N], f[N][20], lson[N << 7], rson[N << 7], root, cnt;
int lazy[N << 7], ans[N << 7], base[N];
int RMQ(int x, int y) {
  int t = base[y - x + 1];
  return min(f[x][t], f[y - (1 << t) + 1][t]);
}
int qry(int l, int r) {
  if (r - l >= n)
    return RMQ(1, n);
  else {
    l = (l - 1) % n + 1, r = (r - 1) % n + 1;
    if (l > r)
      return min(RMQ(1, r), RMQ(l, n));
    else
      return RMQ(l, r);
  }
}
void push_down(int pos) {
  if (!lson[pos]) lson[pos] = ++cnt;
  lazy[lson[pos]] = lazy[pos];
  if (!rson[pos]) rson[pos] = ++cnt;
  lazy[rson[pos]] = lazy[pos];
}
void insert(int l, int r, int &pos, int L, int R, int wei) {
  if (!pos) pos = ++cnt;
  if (lazy[pos] && ~lazy[pos]) {
    ans[pos] = lazy[pos];
    push_down(pos);
    lazy[pos] = -1;
  }
  if (l >= L && r <= R) {
    ans[pos] = lazy[pos] = xx;
    return;
  }
  int mid = (l + r) >> 1;
  if (mid < L)
    insert(mid + 1, r, rson[pos], L, R, wei);
  else if (mid >= R)
    insert(l, mid, lson[pos], L, R, wei);
  else
    insert(l, mid, lson[pos], L, R, wei),
        insert(mid + 1, r, rson[pos], L, R, wei);
  int temp = 0x3f3f3f3f;
  if (lson[pos]) {
    if (!lazy[lson[pos]])
      temp = qry(l, mid);
    else if (lazy[lson[pos]] == -1)
      temp = ans[lson[pos]];
    else
      temp = lazy[lson[pos]];
  } else
    temp = qry(l, mid);
  if (lazy[rson[pos]]) {
    if (!lazy[rson[pos]])
      temp = min(temp, qry(mid + 1, r));
    else if (lazy[rson[pos]] == -1)
      temp = min(temp, ans[rson[pos]]);
    else
      temp = min(temp, lazy[rson[pos]]);
  } else
    temp = min(temp, qry(mid + 1, r));
  ans[pos] = temp, lazy[pos] = -1;
}
int query(int l, int r, int pos, int L, int R) {
  if (l == L && r == R) {
    if (lazy[pos] == -1)
      return ans[pos];
    else if (!lazy[pos])
      return qry(l, r);
    else
      return lazy[pos];
  }
  if (!pos) return qry(L, R);
  if (lazy[pos] && ~lazy[pos]) return lazy[pos];
  int mid = (l + r) >> 1;
  if (mid < L)
    return query(mid + 1, r, rson[pos], L, R);
  else if (mid >= R)
    return query(l, mid, lson[pos], L, R);
  else
    return min(query(l, mid, lson[pos], L, mid),
               query(mid + 1, r, rson[pos], mid + 1, R));
}
void DFS(int l, int r, int pos) {
  printf("l=%d r=%d pos=%d lazy[pos]=%d ans[pos]=%d\n", l, r, pos, lazy[pos],
         ans[pos]);
  int mid = (l + r) >> 1;
  if (lson[pos]) DFS(l, mid, lson[pos]);
  if (rson[pos]) DFS(mid + 1, r, rson[pos]);
}
int main() {
  scanf("%d%d", &n, &k);
  base[0] = -1;
  for (int i = 1; i <= n; i++)
    scanf("%d", &b[i]), f[i][0] = b[i], base[i] = base[i >> 1] + 1;
  for (int j = 1; j <= 19; j++)
    for (int i = 1; i + (1 << (j - 1)) <= n; i++)
      f[i][j] = min(f[i][j - 1], f[i + (1 << (j - 1))][j - 1]);
  scanf("%d", &q);
  while (q--) {
    int l, r;
    scanf("%d%d%d", &op, &l, &r);
    if (op == 1) {
      scanf("%d", &xx);
      insert(1, n * k, root, l, r, xx);
    } else {
      printf("%d\n", query(1, n * k, root, l, r));
    }
  }
}

```