#include <bits/stdc++.h>
using namespace std;
const int Maxn = 100005;
const int Maxm = 2097152;
const int Maxk = 20;
const int Inf = 2000000007;
int n, k;
int b[Maxn][Maxk];
int q;
int typ[Maxn], lef[Maxn], rig[Maxn], x[Maxn];
vector<int> un, seq, vals;
int st[Maxm], flag[Maxm];
int Get(int l, int r) {
  int res = Inf;
  for (int i = Maxk - 1; i >= 0; i--)
    if (l + (1 << i) <= r + 1) {
      res = min(res, b[l][i]);
      l += 1 << i;
    }
  return res;
}
int getBig(int l, int r) {
  if (r - l + 1 >= n) return Get(0, n - 1);
  if (l % n <= r % n) return Get(l % n, r % n);
  return min(Get(l % n, n - 1), Get(0, r % n));
}
void downOn(int v, int val) { st[v] = flag[v] = val; }
void Down(int v) {
  if (flag[v] < Inf) {
    downOn(2 * v, flag[v]);
    downOn(2 * v + 1, flag[v]);
    flag[v] = Inf;
  }
}
void Union(int v) { st[v] = min(st[2 * v], st[2 * v + 1]); }
void Create(int v, int l, int r) {
  flag[v] = Inf;
  if (l == r)
    st[v] = vals[l];
  else {
    int m = l + r >> 1;
    Create(2 * v, l, m);
    Create(2 * v + 1, m + 1, r);
    Union(v);
  }
}
void Update(int v, int l, int r, int a, int b, int x) {
  if (l == a && r == b)
    downOn(v, x);
  else {
    Down(v);
    int m = l + r >> 1;
    if (a <= m) Update(2 * v, l, m, a, min(m, b), x);
    if (m + 1 <= b) Update(2 * v + 1, m + 1, r, max(m + 1, a), b, x);
    Union(v);
  }
}
int Get(int v, int l, int r, int a, int b) {
  if (l == a && r == b)
    return st[v];
  else {
    Down(v);
    int m = l + r >> 1;
    int res = Inf;
    if (a <= m) res = min(res, Get(2 * v, l, m, a, min(m, b)));
    if (m + 1 <= b) res = min(res, Get(2 * v + 1, m + 1, r, max(m + 1, a), b));
    return res;
  }
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", &b[i][0]);
  for (int j = 1; j < Maxk; j++)
    for (int i = 0; i + (1 << j) <= n; i++)
      b[i][j] = min(b[i][j - 1], b[i + (1 << j - 1)][j - 1]);
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d %d %d", &typ[i], &lef[i], &rig[i]);
    lef[i]--;
    rig[i]--;
    if (typ[i] == 1) scanf("%d", &x[i]);
    un.push_back(lef[i]);
    un.push_back(rig[i]);
  }
  sort(un.begin(), un.end());
  un.erase(unique(un.begin(), un.end()), un.end());
  int lst = -1;
  for (int i = 0; i < un.size(); i++) {
    if (lst + 1 < un[i]) {
      seq.push_back(lst + 1);
      vals.push_back(getBig(lst + 1, un[i] - 1));
    }
    seq.push_back(un[i]);
    vals.push_back(b[un[i] % n][0]);
    lst = un[i];
  }
  if (lst + 1 < k * n) {
    seq.push_back(lst + 1);
    vals.push_back(getBig(lst + 1, k * n - 1));
  }
  Create(1, 0, seq.size() - 1);
  for (int i = 0; i < q; i++) {
    lef[i] = lower_bound(seq.begin(), seq.end(), lef[i]) - seq.begin();
    rig[i] = lower_bound(seq.begin(), seq.end(), rig[i]) - seq.begin();
    if (typ[i] == 1)
      Update(1, 0, seq.size() - 1, lef[i], rig[i], x[i]);
    else
      printf("%d\n", Get(1, 0, seq.size() - 1, lef[i], rig[i]));
  }
  return 0;
}

### Prompt

Please formulate 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;
const int Maxn = 100005;
const int Maxm = 2097152;
const int Maxk = 20;
const int Inf = 2000000007;
int n, k;
int b[Maxn][Maxk];
int q;
int typ[Maxn], lef[Maxn], rig[Maxn], x[Maxn];
vector<int> un, seq, vals;
int st[Maxm], flag[Maxm];
int Get(int l, int r) {
  int res = Inf;
  for (int i = Maxk - 1; i >= 0; i--)
    if (l + (1 << i) <= r + 1) {
      res = min(res, b[l][i]);
      l += 1 << i;
    }
  return res;
}
int getBig(int l, int r) {
  if (r - l + 1 >= n) return Get(0, n - 1);
  if (l % n <= r % n) return Get(l % n, r % n);
  return min(Get(l % n, n - 1), Get(0, r % n));
}
void downOn(int v, int val) { st[v] = flag[v] = val; }
void Down(int v) {
  if (flag[v] < Inf) {
    downOn(2 * v, flag[v]);
    downOn(2 * v + 1, flag[v]);
    flag[v] = Inf;
  }
}
void Union(int v) { st[v] = min(st[2 * v], st[2 * v + 1]); }
void Create(int v, int l, int r) {
  flag[v] = Inf;
  if (l == r)
    st[v] = vals[l];
  else {
    int m = l + r >> 1;
    Create(2 * v, l, m);
    Create(2 * v + 1, m + 1, r);
    Union(v);
  }
}
void Update(int v, int l, int r, int a, int b, int x) {
  if (l == a && r == b)
    downOn(v, x);
  else {
    Down(v);
    int m = l + r >> 1;
    if (a <= m) Update(2 * v, l, m, a, min(m, b), x);
    if (m + 1 <= b) Update(2 * v + 1, m + 1, r, max(m + 1, a), b, x);
    Union(v);
  }
}
int Get(int v, int l, int r, int a, int b) {
  if (l == a && r == b)
    return st[v];
  else {
    Down(v);
    int m = l + r >> 1;
    int res = Inf;
    if (a <= m) res = min(res, Get(2 * v, l, m, a, min(m, b)));
    if (m + 1 <= b) res = min(res, Get(2 * v + 1, m + 1, r, max(m + 1, a), b));
    return res;
  }
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", &b[i][0]);
  for (int j = 1; j < Maxk; j++)
    for (int i = 0; i + (1 << j) <= n; i++)
      b[i][j] = min(b[i][j - 1], b[i + (1 << j - 1)][j - 1]);
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d %d %d", &typ[i], &lef[i], &rig[i]);
    lef[i]--;
    rig[i]--;
    if (typ[i] == 1) scanf("%d", &x[i]);
    un.push_back(lef[i]);
    un.push_back(rig[i]);
  }
  sort(un.begin(), un.end());
  un.erase(unique(un.begin(), un.end()), un.end());
  int lst = -1;
  for (int i = 0; i < un.size(); i++) {
    if (lst + 1 < un[i]) {
      seq.push_back(lst + 1);
      vals.push_back(getBig(lst + 1, un[i] - 1));
    }
    seq.push_back(un[i]);
    vals.push_back(b[un[i] % n][0]);
    lst = un[i];
  }
  if (lst + 1 < k * n) {
    seq.push_back(lst + 1);
    vals.push_back(getBig(lst + 1, k * n - 1));
  }
  Create(1, 0, seq.size() - 1);
  for (int i = 0; i < q; i++) {
    lef[i] = lower_bound(seq.begin(), seq.end(), lef[i]) - seq.begin();
    rig[i] = lower_bound(seq.begin(), seq.end(), rig[i]) - seq.begin();
    if (typ[i] == 1)
      Update(1, 0, seq.size() - 1, lef[i], rig[i], x[i]);
    else
      printf("%d\n", Get(1, 0, seq.size() - 1, lef[i], rig[i]));
  }
  return 0;
}

```