#include <bits/stdc++.h>
using namespace std;
int N, K;
int B[100001];
int ST[18][100001];
int sparse_query(int L, int R) {
  int t = log(R - L + 1) / log(2);
  int p = 1 << t;
  return min(ST[t][L], ST[t][R - p + 1]);
}
int direct_query(int L, int R) {
  if (R - L + 1 >= N) return sparse_query(1, N);
  if ((L - 1) / N == (R - 1) / N)
    return sparse_query((L - 1) % N + 1, (R - 1) % N + 1);
  return min(sparse_query((L - 1) % N + 1, N),
             sparse_query(1, (R - 1) % N + 1));
}
class node {
 public:
  int min, lazy;
  node *left, *right;
  node(int L, int R) {
    min = direct_query(L, R);
    lazy = INT_MAX / 2;
    left = right = NULL;
  }
};
void propagate(node*& root, int L, int R) {
  if (root == NULL) root = new node(L, R);
  if (root->lazy == INT_MAX / 2) return;
  root->min = root->lazy;
  if (L != R) {
    int mid = (L + R) / 2;
    if (root->left == NULL) root->left = new node(L, mid);
    if (root->right == NULL) root->right = new node(mid + 1, R);
    root->left->lazy = root->lazy;
    root->right->lazy = root->lazy;
  }
  root->lazy = INT_MAX / 2;
}
void update(node*& root, int L, int R, int qL, int qR, int val) {
  if (root == NULL) root = new node(L, R);
  propagate(root, L, R);
  if (L > qR || R < qL) return;
  if (qL <= L && R <= qR) {
    root->lazy = val;
    propagate(root, L, R);
    return;
  }
  int mid = (L + R) / 2;
  update(root->left, L, mid, qL, qR, val);
  update(root->right, mid + 1, R, qL, qR, val);
  root->min = min(root->left->min, root->right->min);
}
int query(node*& root, int L, int R, int qL, int qR) {
  if (L > qR || R < qL) return INT_MAX / 2;
  if (root == NULL) {
    if (L <= qL && qR <= R) return direct_query(qL, qR);
    if (qL <= L && R <= qR) return direct_query(L, R);
    if (qL <= L && qR <= R) return direct_query(L, qR);
    if (L <= qL && R <= qR) return direct_query(qL, R);
  }
  propagate(root, L, R);
  if (qL <= L && R <= qR) return root->min;
  int mid = (L + R) / 2;
  return min(query(root->left, L, mid, qL, qR),
             query(root->right, mid + 1, R, qL, qR));
}
int main() {
  scanf("%d %d", &N, &K);
  for (int i = 1; i <= N; i++) scanf("%d", &B[i]);
  for (int i = 1; i <= N; i++) ST[0][i] = B[i];
  for (int j = 1; (1 << j) <= N; j++) {
    for (int i = 1; i <= N; i++) {
      ST[j][i] = INT_MAX / 2;
      if (i + (1 << j) - 1 <= N)
        ST[j][i] = min(ST[j - 1][i], ST[j - 1][i + (1 << (j - 1))]);
    }
  }
  int Q;
  scanf("%d", &Q);
  node* root = new node(1, N * K);
  while (Q--) {
    int t;
    scanf("%d", &t);
    if (t == 1) {
      int L, R, x;
      scanf("%d %d %d", &L, &R, &x);
      update(root, 1, N * K, L, R, x);
    } else {
      int L, R;
      scanf("%d %d", &L, &R);
      printf("%d\n", query(root, 1, N * K, L, R));
    }
  }
}

### Prompt

Please provide a CPP coded solution 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>
using namespace std;
int N, K;
int B[100001];
int ST[18][100001];
int sparse_query(int L, int R) {
  int t = log(R - L + 1) / log(2);
  int p = 1 << t;
  return min(ST[t][L], ST[t][R - p + 1]);
}
int direct_query(int L, int R) {
  if (R - L + 1 >= N) return sparse_query(1, N);
  if ((L - 1) / N == (R - 1) / N)
    return sparse_query((L - 1) % N + 1, (R - 1) % N + 1);
  return min(sparse_query((L - 1) % N + 1, N),
             sparse_query(1, (R - 1) % N + 1));
}
class node {
 public:
  int min, lazy;
  node *left, *right;
  node(int L, int R) {
    min = direct_query(L, R);
    lazy = INT_MAX / 2;
    left = right = NULL;
  }
};
void propagate(node*& root, int L, int R) {
  if (root == NULL) root = new node(L, R);
  if (root->lazy == INT_MAX / 2) return;
  root->min = root->lazy;
  if (L != R) {
    int mid = (L + R) / 2;
    if (root->left == NULL) root->left = new node(L, mid);
    if (root->right == NULL) root->right = new node(mid + 1, R);
    root->left->lazy = root->lazy;
    root->right->lazy = root->lazy;
  }
  root->lazy = INT_MAX / 2;
}
void update(node*& root, int L, int R, int qL, int qR, int val) {
  if (root == NULL) root = new node(L, R);
  propagate(root, L, R);
  if (L > qR || R < qL) return;
  if (qL <= L && R <= qR) {
    root->lazy = val;
    propagate(root, L, R);
    return;
  }
  int mid = (L + R) / 2;
  update(root->left, L, mid, qL, qR, val);
  update(root->right, mid + 1, R, qL, qR, val);
  root->min = min(root->left->min, root->right->min);
}
int query(node*& root, int L, int R, int qL, int qR) {
  if (L > qR || R < qL) return INT_MAX / 2;
  if (root == NULL) {
    if (L <= qL && qR <= R) return direct_query(qL, qR);
    if (qL <= L && R <= qR) return direct_query(L, R);
    if (qL <= L && qR <= R) return direct_query(L, qR);
    if (L <= qL && R <= qR) return direct_query(qL, R);
  }
  propagate(root, L, R);
  if (qL <= L && R <= qR) return root->min;
  int mid = (L + R) / 2;
  return min(query(root->left, L, mid, qL, qR),
             query(root->right, mid + 1, R, qL, qR));
}
int main() {
  scanf("%d %d", &N, &K);
  for (int i = 1; i <= N; i++) scanf("%d", &B[i]);
  for (int i = 1; i <= N; i++) ST[0][i] = B[i];
  for (int j = 1; (1 << j) <= N; j++) {
    for (int i = 1; i <= N; i++) {
      ST[j][i] = INT_MAX / 2;
      if (i + (1 << j) - 1 <= N)
        ST[j][i] = min(ST[j - 1][i], ST[j - 1][i + (1 << (j - 1))]);
    }
  }
  int Q;
  scanf("%d", &Q);
  node* root = new node(1, N * K);
  while (Q--) {
    int t;
    scanf("%d", &t);
    if (t == 1) {
      int L, R, x;
      scanf("%d %d %d", &L, &R, &x);
      update(root, 1, N * K, L, R, x);
    } else {
      int L, R;
      scanf("%d %d", &L, &R);
      printf("%d\n", query(root, 1, N * K, L, R));
    }
  }
}

```