#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long inf = 4e18;
const long double pai = acos(-1);
int N, n, k;
int a[100009];
int lg[100009];
int sp[21][100009];
void fill() {
  for (int i = 1; i <= n; i++) {
    int last = lg[i - 1];
    lg[i] = last;
    lg[i] += ((1 << (last + 1)) <= i);
  }
  for (int i = 0; i < n; i++) sp[0][i] = a[i];
  for (int j = 1; j < 21; j++) {
    for (int i = 0; i < n; i++) {
      if (i + (1 << j) - 1 >= n) break;
      sp[j][i] =
          min(sp[j - 1][i], sp[j - 1][(i + (1 << j) - 1) - (1 << (j - 1)) + 1]);
    }
  }
}
int RMQ(int l, int r) {
  int lev = lg[r - l + 1];
  return min(sp[lev][l], sp[lev][r - (1 << lev) + 1]);
}
struct NODE {
  int tree, lzy;
  NODE *left, *right;
  NODE(){};
  NODE(int x) {
    tree = x;
    lzy = 0;
    left = right = NULL;
  };
} * root;
void lzyUPD(NODE *node) {
  if (!node->lzy) return;
  node->left->tree = node->left->lzy = node->lzy;
  node->right->tree = node->right->lzy = node->lzy;
  node->lzy = 0;
}
int Calc(int l, int r) {
  l %= n, r %= n;
  if (l <= r) return RMQ(l, r);
  return min(RMQ(0, r), RMQ(l, n - 1));
}
void upd(NODE *node, int l, int r, int s, int e, int x) {
  if (l > r || s > r || e < l) return;
  if (s <= l && e >= r) {
    node->lzy = x;
    node->tree = x;
    return;
  }
  if (node->left == NULL) {
    int val = Calc(l, (l + r) / 2);
    node->left = new NODE(val);
  }
  if (node->right == NULL) {
    int val = Calc((l + r) / 2 + 1, r);
    node->right = new NODE(val);
  }
  lzyUPD(node);
  upd(node->left, l, (l + r) / 2, s, e, x);
  upd(node->right, (l + r) / 2 + 1, r, s, e, x);
  node->tree = min(node->left->tree, node->right->tree);
}
int query(NODE *node, int l, int r, int s, int e) {
  if (l > r || s > r || e < l) return 1e9;
  if (s <= l && e >= r) return node->tree;
  if (node->left == NULL) {
    int val = ((l + r) / 2 - l + 1 >= n ? RMQ(0, n - 1) : Calc(l, (l + r) / 2));
    node->left = new NODE(val);
  }
  if (node->right == NULL) {
    int val =
        ((l + r) / 2 - l + 1 >= n ? RMQ(0, n - 1) : Calc((l + r) / 2 + 1, r));
    node->right = new NODE(val);
  }
  lzyUPD(node);
  return min(query(node->left, l, (l + r) / 2, s, e),
             query(node->right, (l + r) / 2 + 1, r, s, e));
}
int main() {
  cin >> n >> k;
  N = n * k - 1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  fill();
  root = new NODE(RMQ(0, n - 1));
  int q;
  cin >> q;
  while (q--) {
    int t;
    cin >> t;
    if (t == 1) {
      int l, r, x;
      cin >> l >> r >> x;
      l--, r--;
      upd(root, 0, N, l, r, x);
    } else {
      int l, r;
      cin >> l >> r;
      l--, r--;
      cout << query(root, 0, N, l, r) << endl;
    }
  }
}

### 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;
const long long mod = 1e9 + 7;
const long long inf = 4e18;
const long double pai = acos(-1);
int N, n, k;
int a[100009];
int lg[100009];
int sp[21][100009];
void fill() {
  for (int i = 1; i <= n; i++) {
    int last = lg[i - 1];
    lg[i] = last;
    lg[i] += ((1 << (last + 1)) <= i);
  }
  for (int i = 0; i < n; i++) sp[0][i] = a[i];
  for (int j = 1; j < 21; j++) {
    for (int i = 0; i < n; i++) {
      if (i + (1 << j) - 1 >= n) break;
      sp[j][i] =
          min(sp[j - 1][i], sp[j - 1][(i + (1 << j) - 1) - (1 << (j - 1)) + 1]);
    }
  }
}
int RMQ(int l, int r) {
  int lev = lg[r - l + 1];
  return min(sp[lev][l], sp[lev][r - (1 << lev) + 1]);
}
struct NODE {
  int tree, lzy;
  NODE *left, *right;
  NODE(){};
  NODE(int x) {
    tree = x;
    lzy = 0;
    left = right = NULL;
  };
} * root;
void lzyUPD(NODE *node) {
  if (!node->lzy) return;
  node->left->tree = node->left->lzy = node->lzy;
  node->right->tree = node->right->lzy = node->lzy;
  node->lzy = 0;
}
int Calc(int l, int r) {
  l %= n, r %= n;
  if (l <= r) return RMQ(l, r);
  return min(RMQ(0, r), RMQ(l, n - 1));
}
void upd(NODE *node, int l, int r, int s, int e, int x) {
  if (l > r || s > r || e < l) return;
  if (s <= l && e >= r) {
    node->lzy = x;
    node->tree = x;
    return;
  }
  if (node->left == NULL) {
    int val = Calc(l, (l + r) / 2);
    node->left = new NODE(val);
  }
  if (node->right == NULL) {
    int val = Calc((l + r) / 2 + 1, r);
    node->right = new NODE(val);
  }
  lzyUPD(node);
  upd(node->left, l, (l + r) / 2, s, e, x);
  upd(node->right, (l + r) / 2 + 1, r, s, e, x);
  node->tree = min(node->left->tree, node->right->tree);
}
int query(NODE *node, int l, int r, int s, int e) {
  if (l > r || s > r || e < l) return 1e9;
  if (s <= l && e >= r) return node->tree;
  if (node->left == NULL) {
    int val = ((l + r) / 2 - l + 1 >= n ? RMQ(0, n - 1) : Calc(l, (l + r) / 2));
    node->left = new NODE(val);
  }
  if (node->right == NULL) {
    int val =
        ((l + r) / 2 - l + 1 >= n ? RMQ(0, n - 1) : Calc((l + r) / 2 + 1, r));
    node->right = new NODE(val);
  }
  lzyUPD(node);
  return min(query(node->left, l, (l + r) / 2, s, e),
             query(node->right, (l + r) / 2 + 1, r, s, e));
}
int main() {
  cin >> n >> k;
  N = n * k - 1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  fill();
  root = new NODE(RMQ(0, n - 1));
  int q;
  cin >> q;
  while (q--) {
    int t;
    cin >> t;
    if (t == 1) {
      int l, r, x;
      cin >> l >> r >> x;
      l--, r--;
      upd(root, 0, N, l, r, x);
    } else {
      int l, r;
      cin >> l >> r;
      l--, r--;
      cout << query(root, 0, N, l, r) << endl;
    }
  }
}

```