#include <bits/stdc++.h>
using namespace std;
long long const INF = 2147483647, R_INF = 9223372036854775807, MOD = 1e9 + 7;
const int N = 1e5 + 2, M = 31;
int parent[N][M], input[N];
int n, k;
int f(int x) { return (x - 1) % n + 1; }
struct Node {
  int l, r, lzy, ans;
  Node *lc, *rc;
  Node(int _l, int _r) : l(_l), r(_r), lzy(), lc(), rc() {
    int j = log2(r - l + 1);
    ans = min(parent[f(l)][j], parent[f(r - (1 << j) + 1)][j]);
  }
} * root;
void build() {
  for (int i = 1; i < n + 1; i++) parent[i][0] = input[i];
  for (int j = 1; j < M; j++)
    for (int i = 1; i < n + 1; i++)
      parent[i][j] =
          min(parent[i][j - 1], parent[f(i + (1 << (j - 1)))][j - 1]);
}
void new_Node(Node *cur) {
  int m = (cur->l + cur->r) / 2;
  if (cur->lc == NULL) cur->lc = new Node(cur->l, m);
  if (cur->rc == NULL) cur->rc = new Node(m + 1, cur->r);
  if (cur->lzy == 0) return;
  cur->lc->ans = cur->lc->lzy = cur->lzy;
  cur->rc->ans = cur->rc->lzy = cur->lzy;
  cur->lzy = 0;
}
void update(int l, int r, int x, Node *cur = root) {
  if (cur->l > r || cur->r < l) return;
  if (cur->l >= l && cur->r <= r) {
    cur->ans = cur->lzy = x;
    return;
  }
  new_Node(cur);
  update(l, r, x, cur->lc);
  update(l, r, x, cur->rc);
  cur->ans = min(cur->lc->ans, cur->rc->ans);
}
int query(int l, int r, Node *cur = root) {
  if (cur->l > r || cur->r < l) return INF;
  if (cur->l >= l && cur->r <= r) return cur->ans;
  new_Node(cur);
  return min(query(l, r, cur->lc), query(l, r, cur->rc));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> k;
  for (int i = 1; i < n + 1; i++) cin >> input[i];
  build();
  root = new Node(1, n * k);
  int q;
  cin >> q;
  while (q--) {
    int type, l, r, x;
    cin >> type >> l >> r;
    if (type == 1) {
      cin >> x;
      update(l, r, x);
    } else
      cout << query(l, r) << '\n';
  }
}

### 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;
long long const INF = 2147483647, R_INF = 9223372036854775807, MOD = 1e9 + 7;
const int N = 1e5 + 2, M = 31;
int parent[N][M], input[N];
int n, k;
int f(int x) { return (x - 1) % n + 1; }
struct Node {
  int l, r, lzy, ans;
  Node *lc, *rc;
  Node(int _l, int _r) : l(_l), r(_r), lzy(), lc(), rc() {
    int j = log2(r - l + 1);
    ans = min(parent[f(l)][j], parent[f(r - (1 << j) + 1)][j]);
  }
} * root;
void build() {
  for (int i = 1; i < n + 1; i++) parent[i][0] = input[i];
  for (int j = 1; j < M; j++)
    for (int i = 1; i < n + 1; i++)
      parent[i][j] =
          min(parent[i][j - 1], parent[f(i + (1 << (j - 1)))][j - 1]);
}
void new_Node(Node *cur) {
  int m = (cur->l + cur->r) / 2;
  if (cur->lc == NULL) cur->lc = new Node(cur->l, m);
  if (cur->rc == NULL) cur->rc = new Node(m + 1, cur->r);
  if (cur->lzy == 0) return;
  cur->lc->ans = cur->lc->lzy = cur->lzy;
  cur->rc->ans = cur->rc->lzy = cur->lzy;
  cur->lzy = 0;
}
void update(int l, int r, int x, Node *cur = root) {
  if (cur->l > r || cur->r < l) return;
  if (cur->l >= l && cur->r <= r) {
    cur->ans = cur->lzy = x;
    return;
  }
  new_Node(cur);
  update(l, r, x, cur->lc);
  update(l, r, x, cur->rc);
  cur->ans = min(cur->lc->ans, cur->rc->ans);
}
int query(int l, int r, Node *cur = root) {
  if (cur->l > r || cur->r < l) return INF;
  if (cur->l >= l && cur->r <= r) return cur->ans;
  new_Node(cur);
  return min(query(l, r, cur->lc), query(l, r, cur->rc));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> k;
  for (int i = 1; i < n + 1; i++) cin >> input[i];
  build();
  root = new Node(1, n * k);
  int q;
  cin >> q;
  while (q--) {
    int type, l, r, x;
    cin >> type >> l >> r;
    if (type == 1) {
      cin >> x;
      update(l, r, x);
    } else
      cout << query(l, r) << '\n';
  }
}

```