#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
int i, j, k, n, m, z, lg[N], f[N][17], lab, RT, ls[N * 90], rs[N * 90],
    d[N * 90], cv[N * 90];
int MIN(int l, int r) {
  int x = lg[r - l];
  return min(f[l][x], f[r - (1 << x) + 1][x]);
}
int cal(int l, int r) {
  if (r - l + 1 >= n) return MIN(0, n - 1);
  return l / n == r / n ? MIN(l % n, r % n)
                        : min(MIN(l % n, n - 1), MIN(0, r % n));
}
void pdn(int p) {
  if (!cv[p]) return;
  if (!ls[p]) ls[p] = ++lab;
  if (!rs[p]) rs[p] = ++lab;
  d[ls[p]] = d[rs[p]] = cv[ls[p]] = cv[rs[p]] = cv[p], cv[p] = 0;
}
int A(int& p, int L, int R, int l, int r) {
  if (!p) p = ++lab, d[p] = cal(L, R);
  if (L == l && R == r) return d[p] = cv[p] = z;
  int m = L + R >> 1;
  if (pdn(p), r <= m)
    A(ls[p], L, m, l, r);
  else if (l > m)
    A(rs[p], m + 1, R, l, r);
  else
    A(ls[p], L, m, l, m), A(rs[p], m + 1, R, m + 1, r);
  if (!ls[p]) d[ls[p] = ++lab] = cal(L, m);
  if (!rs[p]) d[rs[p] = ++lab] = cal(m + 1, R);
  d[p] = min(d[ls[p]], d[rs[p]]);
}
int Q(int p, int L, int R, int l, int r) {
  if (!p) p = ++lab, d[p] = cal(L, R);
  if (L == l && R == r) return d[p];
  int m = L + R >> 1;
  if (pdn(p), r <= m) return Q(ls[p], L, m, l, r);
  if (l > m) return Q(rs[p], m + 1, R, l, r);
  return min(Q(ls[p], L, m, l, m), Q(rs[p], m + 1, R, m + 1, r));
}
int main() {
  scanf("%d%d", &n, &k);
  for (i = 2; i <= n; ++i) lg[i] = lg[i >> 1] + 1;
  for (i = 0; i < n; ++i) scanf("%d", f[i]);
  for (j = 1; j <= lg[n]; ++j)
    for (i = 0; i + (1 << j) <= n; ++i)
      f[i][j] = min(f[i][j - 1], f[i + (1 << j - 1)][j - 1]);
  for (scanf("%d", &m); m--;) {
    scanf("%d%d%d", &z, &i, &j);
    if (z > 1)
      printf("%d\n", Q(RT, 0, n * k - 1, i - 1, j - 1));
    else
      scanf("%d", &z), A(RT, 0, n * k - 1, i - 1, j - 1);
  }
}

### Prompt

Generate 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 N = 1e5 + 1;
int i, j, k, n, m, z, lg[N], f[N][17], lab, RT, ls[N * 90], rs[N * 90],
    d[N * 90], cv[N * 90];
int MIN(int l, int r) {
  int x = lg[r - l];
  return min(f[l][x], f[r - (1 << x) + 1][x]);
}
int cal(int l, int r) {
  if (r - l + 1 >= n) return MIN(0, n - 1);
  return l / n == r / n ? MIN(l % n, r % n)
                        : min(MIN(l % n, n - 1), MIN(0, r % n));
}
void pdn(int p) {
  if (!cv[p]) return;
  if (!ls[p]) ls[p] = ++lab;
  if (!rs[p]) rs[p] = ++lab;
  d[ls[p]] = d[rs[p]] = cv[ls[p]] = cv[rs[p]] = cv[p], cv[p] = 0;
}
int A(int& p, int L, int R, int l, int r) {
  if (!p) p = ++lab, d[p] = cal(L, R);
  if (L == l && R == r) return d[p] = cv[p] = z;
  int m = L + R >> 1;
  if (pdn(p), r <= m)
    A(ls[p], L, m, l, r);
  else if (l > m)
    A(rs[p], m + 1, R, l, r);
  else
    A(ls[p], L, m, l, m), A(rs[p], m + 1, R, m + 1, r);
  if (!ls[p]) d[ls[p] = ++lab] = cal(L, m);
  if (!rs[p]) d[rs[p] = ++lab] = cal(m + 1, R);
  d[p] = min(d[ls[p]], d[rs[p]]);
}
int Q(int p, int L, int R, int l, int r) {
  if (!p) p = ++lab, d[p] = cal(L, R);
  if (L == l && R == r) return d[p];
  int m = L + R >> 1;
  if (pdn(p), r <= m) return Q(ls[p], L, m, l, r);
  if (l > m) return Q(rs[p], m + 1, R, l, r);
  return min(Q(ls[p], L, m, l, m), Q(rs[p], m + 1, R, m + 1, r));
}
int main() {
  scanf("%d%d", &n, &k);
  for (i = 2; i <= n; ++i) lg[i] = lg[i >> 1] + 1;
  for (i = 0; i < n; ++i) scanf("%d", f[i]);
  for (j = 1; j <= lg[n]; ++j)
    for (i = 0; i + (1 << j) <= n; ++i)
      f[i][j] = min(f[i][j - 1], f[i + (1 << j - 1)][j - 1]);
  for (scanf("%d", &m); m--;) {
    scanf("%d%d%d", &z, &i, &j);
    if (z > 1)
      printf("%d\n", Q(RT, 0, n * k - 1, i - 1, j - 1));
    else
      scanf("%d", &z), A(RT, 0, n * k - 1, i - 1, j - 1);
  }
}

```