#include <bits/stdc++.h>
using namespace std;
const int inf = INT_MAX, N = 1e5 + 5;
int n, k, q, l, r, type, x, step[N], sp[31][N];
inline int kek(int x) { return (x + n - 1) / n; }
inline int get(int l, int r) {
  int x = step[r - l + 1];
  return min(sp[x][l], sp[x][r - (1 << x) + 1]);
}
inline int get_sp(int l, int r) {
  if (kek(l) == kek(r)) {
    return get((l - 1) % n + 1, (r - 1) % n + 1);
  } else if (kek(r) - kek(l) > 1) {
    return get(1, n);
  } else {
    return min(get((l - 1) % n + 1, n), get(1, (r - 1) % n + 1));
  }
}
struct item {
  item *l, *r;
  int add, mn;
  item(int tl, int tr) {
    l = r = nullptr;
    add = -1;
    mn = get_sp(tl, tr);
  }
};
typedef item *node;
inline void push(node v, int l, int r) {
  if (!v || v->add == -1) {
    return;
  }
  if (l != r) {
    int mid = (r + l) >> 1;
    if (!v->l) {
      v->l = new item(l, mid);
    }
    v->l->add = v->add;
    if (!v->r) {
      v->r = new item(mid + 1, r);
    }
    v->r->add = v->add;
  }
  v->mn = v->add;
  v->add = -1;
}
void update(node v, int l, int r, int tl, int tr, int val) {
  push(v, l, r);
  if (l > r || l > tr || tl > r) {
    return;
  }
  if (tl <= l && r <= tr) {
    v->add = val;
    push(v, l, r);
    return;
  }
  int mid = (r + l) >> 1;
  if (!v->l) {
    v->l = new item(l, mid);
  }
  if (!v->r) {
    v->r = new item(mid + 1, r);
  }
  update(v->l, l, mid, tl, tr, val);
  update(v->r, mid + 1, r, tl, tr, val);
  v->mn = min(v->l->mn, v->r->mn);
}
int get_min(node v, int l, int r, int tl, int tr) {
  push(v, l, r);
  if (l > r || l > tr || tl > r) {
    return inf;
  }
  if (!v) {
    return get_sp(max(l, tl), min(r, tr));
  } else {
    if (tl <= l && r <= tr) {
      return v->mn;
    }
    int mid = (r + l) >> 1;
    return min(get_min(v->l, l, mid, tl, tr),
               get_min(v->r, mid + 1, r, tl, tr));
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    sp[0][i] = x;
    if (i > 1) {
      step[i] = step[i / 2] + 1;
    }
  }
  for (int i = 1; i <= step[n]; i++) {
    for (int j = 1; j + (1 << i) - 1 <= n; j++) {
      sp[i][j] = min(sp[i - 1][j], sp[i - 1][j + (1 << (i - 1))]);
    }
  }
  node root = new item(1, n * k);
  cin >> q;
  while (q--) {
    cin >> type >> l >> r;
    if (type == 1) {
      cin >> x;
      update(root, 1, n * k, l, r, x);
    } else {
      cout << get_min(root, 1, n * k, l, r) << "\n";
    }
  }
}

### Prompt

Please create a solution in Cpp 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 inf = INT_MAX, N = 1e5 + 5;
int n, k, q, l, r, type, x, step[N], sp[31][N];
inline int kek(int x) { return (x + n - 1) / n; }
inline int get(int l, int r) {
  int x = step[r - l + 1];
  return min(sp[x][l], sp[x][r - (1 << x) + 1]);
}
inline int get_sp(int l, int r) {
  if (kek(l) == kek(r)) {
    return get((l - 1) % n + 1, (r - 1) % n + 1);
  } else if (kek(r) - kek(l) > 1) {
    return get(1, n);
  } else {
    return min(get((l - 1) % n + 1, n), get(1, (r - 1) % n + 1));
  }
}
struct item {
  item *l, *r;
  int add, mn;
  item(int tl, int tr) {
    l = r = nullptr;
    add = -1;
    mn = get_sp(tl, tr);
  }
};
typedef item *node;
inline void push(node v, int l, int r) {
  if (!v || v->add == -1) {
    return;
  }
  if (l != r) {
    int mid = (r + l) >> 1;
    if (!v->l) {
      v->l = new item(l, mid);
    }
    v->l->add = v->add;
    if (!v->r) {
      v->r = new item(mid + 1, r);
    }
    v->r->add = v->add;
  }
  v->mn = v->add;
  v->add = -1;
}
void update(node v, int l, int r, int tl, int tr, int val) {
  push(v, l, r);
  if (l > r || l > tr || tl > r) {
    return;
  }
  if (tl <= l && r <= tr) {
    v->add = val;
    push(v, l, r);
    return;
  }
  int mid = (r + l) >> 1;
  if (!v->l) {
    v->l = new item(l, mid);
  }
  if (!v->r) {
    v->r = new item(mid + 1, r);
  }
  update(v->l, l, mid, tl, tr, val);
  update(v->r, mid + 1, r, tl, tr, val);
  v->mn = min(v->l->mn, v->r->mn);
}
int get_min(node v, int l, int r, int tl, int tr) {
  push(v, l, r);
  if (l > r || l > tr || tl > r) {
    return inf;
  }
  if (!v) {
    return get_sp(max(l, tl), min(r, tr));
  } else {
    if (tl <= l && r <= tr) {
      return v->mn;
    }
    int mid = (r + l) >> 1;
    return min(get_min(v->l, l, mid, tl, tr),
               get_min(v->r, mid + 1, r, tl, tr));
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    sp[0][i] = x;
    if (i > 1) {
      step[i] = step[i / 2] + 1;
    }
  }
  for (int i = 1; i <= step[n]; i++) {
    for (int j = 1; j + (1 << i) - 1 <= n; j++) {
      sp[i][j] = min(sp[i - 1][j], sp[i - 1][j + (1 << (i - 1))]);
    }
  }
  node root = new item(1, n * k);
  cin >> q;
  while (q--) {
    cin >> type >> l >> r;
    if (type == 1) {
      cin >> x;
      update(root, 1, n * k, l, r, x);
    } else {
      cout << get_min(root, 1, n * k, l, r) << "\n";
    }
  }
}

```