#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool mini(T &a, T b) {
  return b < a ? a = b, true : false;
}
template <typename T>
inline bool maxi(T &a, T b) {
  return a < b ? a = b, true : false;
}
const int N = 1 << 17, INF = int(2e9);
int a[18][N];
int MinA = INF;
int n, k;
int _rmq(int L, int R) {
  int len = R - L + 1;
  int k = 1, c = 0;
  while ((k << 1) <= len) k <<= 1, c++;
  return min(a[c][L], a[c][R - (1 << c) + 1]);
}
int rmq(int L, int R) {
  if (R - L + 1 >= n) return MinA;
  R--, R %= n, R++;
  L--, L %= n, L++;
  if (L <= R)
    return _rmq(L, R);
  else
    return min(_rmq(L, n), _rmq(1, R));
}
struct node {
  int Min = INF;
  int Lazy = INF;
  node *_L = NULL, *_R = NULL;
  node &L(int L, int R) {
    if (!_L) _L = new node, _L->Min = rmq(L, R);
    return *_L;
  }
  node &R(int L, int R) {
    if (!_R) _R = new node, _R->Min = rmq(L, R);
    return *_R;
  }
  void Set(int val) {
    Min = val;
    Lazy = val;
  }
};
void Push(node &x, int L, int R) {
  if (L == R || x.Lazy == INF) return;
  int m = (L + R) / 2;
  x.L(L, m).Set(x.Lazy);
  x.R(m + 1, R).Set(x.Lazy);
  x.Lazy = INF;
}
void Update(node &x, int L, int R, int u, int v, int val) {
  if (R < u || L > v) return;
  Push(x, L, R);
  if (u <= L && R <= v) {
    x.Set(val);
  } else {
    int m = (L + R) / 2;
    Update(x.L(L, m), L, m, u, v, val);
    Update(x.R(m + 1, R), m + 1, R, u, v, val);
    x.Min = min(x._L->Min, x._R->Min);
  }
}
int Query(node &x, int L, int R, int u, int v) {
  if (R < u || L > v) return INF;
  Push(x, L, R);
  if (u <= L && R <= v) {
    return x.Min;
  } else {
    int m = (L + R) / 2;
    int qL = Query(x.L(L, m), L, m, u, v);
    int qR = Query(x.R(m + 1, R), m + 1, R, u, v);
    return min(qL, qR);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = (1); i <= (int)(n); i++) cin >> a[0][i], mini(MinA, a[0][i]);
  for (int i = (1); i <= (int)(17); i++) {
    int st = 1 << i, st1 = 1 << (i - 1);
    for (int j = (1); j <= (int)(n - st + 1); j++)
      a[i][j] = min(a[i - 1][j], a[i - 1][j + st1]);
  }
  node root;
  root.Min = MinA;
  int q;
  cin >> q;
  for (int i = 0; i < (int)(q); i++) {
    int t, x, y;
    cin >> t >> x >> y;
    if (t == 1) {
      int v;
      cin >> v;
      Update(root, 1, n * k, x, y, v);
    } else {
      int r = Query(root, 1, n * k, x, y);
      cout << r << '\n';
    }
  }
  return 0;
}

### Prompt

Develop a solution in Cpp 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;
template <typename T>
inline bool mini(T &a, T b) {
  return b < a ? a = b, true : false;
}
template <typename T>
inline bool maxi(T &a, T b) {
  return a < b ? a = b, true : false;
}
const int N = 1 << 17, INF = int(2e9);
int a[18][N];
int MinA = INF;
int n, k;
int _rmq(int L, int R) {
  int len = R - L + 1;
  int k = 1, c = 0;
  while ((k << 1) <= len) k <<= 1, c++;
  return min(a[c][L], a[c][R - (1 << c) + 1]);
}
int rmq(int L, int R) {
  if (R - L + 1 >= n) return MinA;
  R--, R %= n, R++;
  L--, L %= n, L++;
  if (L <= R)
    return _rmq(L, R);
  else
    return min(_rmq(L, n), _rmq(1, R));
}
struct node {
  int Min = INF;
  int Lazy = INF;
  node *_L = NULL, *_R = NULL;
  node &L(int L, int R) {
    if (!_L) _L = new node, _L->Min = rmq(L, R);
    return *_L;
  }
  node &R(int L, int R) {
    if (!_R) _R = new node, _R->Min = rmq(L, R);
    return *_R;
  }
  void Set(int val) {
    Min = val;
    Lazy = val;
  }
};
void Push(node &x, int L, int R) {
  if (L == R || x.Lazy == INF) return;
  int m = (L + R) / 2;
  x.L(L, m).Set(x.Lazy);
  x.R(m + 1, R).Set(x.Lazy);
  x.Lazy = INF;
}
void Update(node &x, int L, int R, int u, int v, int val) {
  if (R < u || L > v) return;
  Push(x, L, R);
  if (u <= L && R <= v) {
    x.Set(val);
  } else {
    int m = (L + R) / 2;
    Update(x.L(L, m), L, m, u, v, val);
    Update(x.R(m + 1, R), m + 1, R, u, v, val);
    x.Min = min(x._L->Min, x._R->Min);
  }
}
int Query(node &x, int L, int R, int u, int v) {
  if (R < u || L > v) return INF;
  Push(x, L, R);
  if (u <= L && R <= v) {
    return x.Min;
  } else {
    int m = (L + R) / 2;
    int qL = Query(x.L(L, m), L, m, u, v);
    int qR = Query(x.R(m + 1, R), m + 1, R, u, v);
    return min(qL, qR);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = (1); i <= (int)(n); i++) cin >> a[0][i], mini(MinA, a[0][i]);
  for (int i = (1); i <= (int)(17); i++) {
    int st = 1 << i, st1 = 1 << (i - 1);
    for (int j = (1); j <= (int)(n - st + 1); j++)
      a[i][j] = min(a[i - 1][j], a[i - 1][j + st1]);
  }
  node root;
  root.Min = MinA;
  int q;
  cin >> q;
  for (int i = 0; i < (int)(q); i++) {
    int t, x, y;
    cin >> t >> x >> y;
    if (t == 1) {
      int v;
      cin >> v;
      Update(root, 1, n * k, x, y, v);
    } else {
      int r = Query(root, 1, n * k, x, y);
      cout << r << '\n';
    }
  }
  return 0;
}

```