#include <bits/stdc++.h>
using namespace std;
int getMin(int l, int r);
const int MAXN = 1e5 + 100, LOG = 19, B = 31;
int ar[MAXN * 2], tb[MAXN * 2][LOG], d[B];
int n, k, q;
struct Node {
  Node *l = nullptr, *r = nullptr;
  int mn = -1, val = 1e9;

 public:
  Node(int l, int r) { val = getMin(l, r); }
};
Node *root = nullptr;
int getMin(int l, int r) {
  if (r - l >= n) {
    l = 0;
    r = n - 1;
  } else {
    r -= l / n * n;
    l %= n;
  }
  int b = 0, e = B;
  while (e - b > 1) {
    int p = (e + b) / 2;
    if (d[p] <= r - l + 1)
      b = p;
    else
      e = p;
  }
  int ans = min(tb[l][b], tb[r - (1 << b) + 1][b]);
  return ans;
}
void push(Node *cur, int l, int r) {
  if (cur->mn != -1) cur->val = cur->mn;
  if (l != r) {
    int m = (l + r) / 2;
    if (cur->l == nullptr) cur->l = new Node(l, m);
    if (cur->r == nullptr) cur->r = new Node(m + 1, r);
    if (cur->mn != -1) cur->l->mn = cur->r->mn = cur->mn;
  }
  cur->mn = -1;
}
void update(Node *cur, int l, int r, int tl, int tr, int val) {
  push(cur, tl, tr);
  if (tl == l && tr == r) {
    cur->mn = val;
  } else {
    int m = (tr + tl) / 2;
    if (l <= m) {
      update(cur->l, l, min(m, r), tl, m, val);
    }
    if (r > m) {
      update(cur->r, max(l, m + 1), r, m + 1, tr, val);
    }
    push(cur->l, tl, m);
    push(cur->r, m + 1, tr);
    cur->val = min(cur->l->val, cur->r->val);
  }
}
int getAns(Node *cur, int l, int r, int tl, int tr) {
  push(cur, tl, tr);
  if (l == tl && r == tr) {
    return cur->val;
  }
  int m = (tl + tr) / 2, ans = 1e9;
  if (m >= l) {
    ans = min(getAns(cur->l, l, min(m, r), tl, m), ans);
  }
  if (r > m) {
    ans = min(getAns(cur->r, max(l, m + 1), r, m + 1, tr), ans);
  }
  return ans;
}
int main() {
#pragma warning(disable : 4996)
  d[0] = 1;
  for (int i = 0; i < B - 1; i++) {
    d[i + 1] = d[i] * 2;
  }
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", &ar[i]);
    ar[i + n] = ar[i];
    tb[i][0] = tb[i + n][0] = ar[i];
  }
  for (int i = 1; i < LOG; i++) {
    for (int j = 0; j < n * 2 && j + (1 << (i)) - 1 < n * 2; j++) {
      tb[j][i] = min(tb[j][i - 1], tb[j + (1 << (i - 1))][i - 1]);
    }
  }
  root = new Node(0, n * k - 1);
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int c, l, r, x;
    scanf("%d", &c);
    if (c == 1) {
      scanf("%d%d%d", &l, &r, &x);
      update(root, l - 1, r - 1, 0, n * k - 1, x);
    } else {
      scanf("%d%d", &l, &r);
      printf("%d\n", getAns(root, l - 1, r - 1, 0, n * k - 1));
    }
  }
  return 0;
}

### 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 getMin(int l, int r);
const int MAXN = 1e5 + 100, LOG = 19, B = 31;
int ar[MAXN * 2], tb[MAXN * 2][LOG], d[B];
int n, k, q;
struct Node {
  Node *l = nullptr, *r = nullptr;
  int mn = -1, val = 1e9;

 public:
  Node(int l, int r) { val = getMin(l, r); }
};
Node *root = nullptr;
int getMin(int l, int r) {
  if (r - l >= n) {
    l = 0;
    r = n - 1;
  } else {
    r -= l / n * n;
    l %= n;
  }
  int b = 0, e = B;
  while (e - b > 1) {
    int p = (e + b) / 2;
    if (d[p] <= r - l + 1)
      b = p;
    else
      e = p;
  }
  int ans = min(tb[l][b], tb[r - (1 << b) + 1][b]);
  return ans;
}
void push(Node *cur, int l, int r) {
  if (cur->mn != -1) cur->val = cur->mn;
  if (l != r) {
    int m = (l + r) / 2;
    if (cur->l == nullptr) cur->l = new Node(l, m);
    if (cur->r == nullptr) cur->r = new Node(m + 1, r);
    if (cur->mn != -1) cur->l->mn = cur->r->mn = cur->mn;
  }
  cur->mn = -1;
}
void update(Node *cur, int l, int r, int tl, int tr, int val) {
  push(cur, tl, tr);
  if (tl == l && tr == r) {
    cur->mn = val;
  } else {
    int m = (tr + tl) / 2;
    if (l <= m) {
      update(cur->l, l, min(m, r), tl, m, val);
    }
    if (r > m) {
      update(cur->r, max(l, m + 1), r, m + 1, tr, val);
    }
    push(cur->l, tl, m);
    push(cur->r, m + 1, tr);
    cur->val = min(cur->l->val, cur->r->val);
  }
}
int getAns(Node *cur, int l, int r, int tl, int tr) {
  push(cur, tl, tr);
  if (l == tl && r == tr) {
    return cur->val;
  }
  int m = (tl + tr) / 2, ans = 1e9;
  if (m >= l) {
    ans = min(getAns(cur->l, l, min(m, r), tl, m), ans);
  }
  if (r > m) {
    ans = min(getAns(cur->r, max(l, m + 1), r, m + 1, tr), ans);
  }
  return ans;
}
int main() {
#pragma warning(disable : 4996)
  d[0] = 1;
  for (int i = 0; i < B - 1; i++) {
    d[i + 1] = d[i] * 2;
  }
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", &ar[i]);
    ar[i + n] = ar[i];
    tb[i][0] = tb[i + n][0] = ar[i];
  }
  for (int i = 1; i < LOG; i++) {
    for (int j = 0; j < n * 2 && j + (1 << (i)) - 1 < n * 2; j++) {
      tb[j][i] = min(tb[j][i - 1], tb[j + (1 << (i - 1))][i - 1]);
    }
  }
  root = new Node(0, n * k - 1);
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int c, l, r, x;
    scanf("%d", &c);
    if (c == 1) {
      scanf("%d%d%d", &l, &r, &x);
      update(root, l - 1, r - 1, 0, n * k - 1, x);
    } else {
      scanf("%d%d", &l, &r);
      printf("%d\n", getAns(root, l - 1, r - 1, 0, n * k - 1));
    }
  }
  return 0;
}

```