#include <bits/stdc++.h>
int inp() {
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  int sum = 0;
  while (c >= '0' && c <= '9') {
    sum = sum * 10 + c - '0';
    c = getchar();
  }
  return sum;
}
int min[200010][24];
int n;
int rmq(int l, int r) {
  l = (l - 1) % n + 1;
  r = (r - 1) % n + 1;
  int lg = log2(r - l + 1);
  return std::min(min[l][lg], min[r - (1 << lg) + 1][lg]);
}
struct SEG_Tree {
  int min[5000000];
  int lc[5000000];
  int rc[5000000];
  int lazy[5000000];
  int cnt = 0;
  void push_up(int cur) { min[cur] = std::min(min[lc[cur]], min[rc[cur]]); }
  void modify(int &cur, int ql, int qr, int l, int r, int c, int fa) {
    if (cur == 0) {
      cur = ++cnt;
      lc[cur] = rc[cur] = 0;
      if ((qr - 1) / n == (ql - 1) / n)
        min[cur] = rmq(ql, qr);
      else if ((qr - 1) / n == (ql - 1) / n + 1)
        min[cur] = std::min(rmq(ql, n), rmq(1, qr));
      else
        min[cur] = rmq(1, n);
    }
    if (lazy[fa]) min[cur] = lazy[cur] = lazy[fa];
    if (ql > r || qr < l) return;
    if (ql >= l && qr <= r) {
      min[cur] = c;
      lazy[cur] = c;
      return;
    }
    int mid = (ql + qr) >> 1;
    modify(lc[cur], ql, mid, l, r, c, cur);
    modify(rc[cur], mid + 1, qr, l, r, c, cur);
    lazy[cur] = 0;
    push_up(cur);
  }
  int query(int &cur, int ql, int qr, int l, int r, int fa) {
    if (cur == 0) {
      cur = ++cnt;
      lc[cur] = rc[cur] = 0;
      if ((qr - 1) / n == (ql - 1) / n)
        min[cur] = rmq(ql, qr);
      else if ((qr - 1) / n == (ql - 1) / n + 1)
        min[cur] = std::min(rmq(ql, n), rmq(1, qr));
      else
        min[cur] = rmq(1, n);
    }
    if (lazy[fa]) min[cur] = lazy[cur] = lazy[fa];
    if (ql > r || qr < l) return 2147483647;
    if (ql >= l && qr <= r) return min[cur];
    int mid = (ql + qr) >> 1;
    return std::min(query(lc[cur], ql, mid, l, r, cur),
                    query(rc[cur], mid + 1, qr, l, r, cur));
  }
} t;
int main() {
  t.min[0] = 2147483647;
  n = inp();
  int k = inp();
  int len = n * k;
  for (int i = 1; i <= n; i++) min[i][0] = inp();
  for (int j = 1; j <= 20; j++)
    for (int i = 1; i <= n; i++)
      if (i + (1 << j) - 1 <= n)
        min[i][j] = std::min(min[i][j - 1], min[i + (1 << (j - 1))][j - 1]);
  int m = inp();
  int root = 0;
  while (m--) {
    int op = inp();
    if (op == 1) {
      int l = inp();
      int r = inp();
      int c = inp();
      t.modify(root, 1, len, l, r, c, 0);
    } else {
      int l = inp();
      int r = inp();
      printf("%d\n", t.query(root, 1, len, l, r, 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>
int inp() {
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  int sum = 0;
  while (c >= '0' && c <= '9') {
    sum = sum * 10 + c - '0';
    c = getchar();
  }
  return sum;
}
int min[200010][24];
int n;
int rmq(int l, int r) {
  l = (l - 1) % n + 1;
  r = (r - 1) % n + 1;
  int lg = log2(r - l + 1);
  return std::min(min[l][lg], min[r - (1 << lg) + 1][lg]);
}
struct SEG_Tree {
  int min[5000000];
  int lc[5000000];
  int rc[5000000];
  int lazy[5000000];
  int cnt = 0;
  void push_up(int cur) { min[cur] = std::min(min[lc[cur]], min[rc[cur]]); }
  void modify(int &cur, int ql, int qr, int l, int r, int c, int fa) {
    if (cur == 0) {
      cur = ++cnt;
      lc[cur] = rc[cur] = 0;
      if ((qr - 1) / n == (ql - 1) / n)
        min[cur] = rmq(ql, qr);
      else if ((qr - 1) / n == (ql - 1) / n + 1)
        min[cur] = std::min(rmq(ql, n), rmq(1, qr));
      else
        min[cur] = rmq(1, n);
    }
    if (lazy[fa]) min[cur] = lazy[cur] = lazy[fa];
    if (ql > r || qr < l) return;
    if (ql >= l && qr <= r) {
      min[cur] = c;
      lazy[cur] = c;
      return;
    }
    int mid = (ql + qr) >> 1;
    modify(lc[cur], ql, mid, l, r, c, cur);
    modify(rc[cur], mid + 1, qr, l, r, c, cur);
    lazy[cur] = 0;
    push_up(cur);
  }
  int query(int &cur, int ql, int qr, int l, int r, int fa) {
    if (cur == 0) {
      cur = ++cnt;
      lc[cur] = rc[cur] = 0;
      if ((qr - 1) / n == (ql - 1) / n)
        min[cur] = rmq(ql, qr);
      else if ((qr - 1) / n == (ql - 1) / n + 1)
        min[cur] = std::min(rmq(ql, n), rmq(1, qr));
      else
        min[cur] = rmq(1, n);
    }
    if (lazy[fa]) min[cur] = lazy[cur] = lazy[fa];
    if (ql > r || qr < l) return 2147483647;
    if (ql >= l && qr <= r) return min[cur];
    int mid = (ql + qr) >> 1;
    return std::min(query(lc[cur], ql, mid, l, r, cur),
                    query(rc[cur], mid + 1, qr, l, r, cur));
  }
} t;
int main() {
  t.min[0] = 2147483647;
  n = inp();
  int k = inp();
  int len = n * k;
  for (int i = 1; i <= n; i++) min[i][0] = inp();
  for (int j = 1; j <= 20; j++)
    for (int i = 1; i <= n; i++)
      if (i + (1 << j) - 1 <= n)
        min[i][j] = std::min(min[i][j - 1], min[i + (1 << (j - 1))][j - 1]);
  int m = inp();
  int root = 0;
  while (m--) {
    int op = inp();
    if (op == 1) {
      int l = inp();
      int r = inp();
      int c = inp();
      t.modify(root, 1, len, l, r, c, 0);
    } else {
      int l = inp();
      int r = inp();
      printf("%d\n", t.query(root, 1, len, l, r, 0));
    }
  }
}

```