#include <bits/stdc++.h>
using namespace std;
template <class T>
T Bitcnt(T a) {
  int sum = 0;
  while (a) {
    if (a & 1) sum++;
    a /= 2;
  }
  return sum;
}
template <class T>
T Max3(T a, T b, T c) {
  return max(a, max(b, c));
}
template <class T>
T Lcm(T a, T b) {
  T tmp = __gcd(a, b);
  return (a / tmp) * b;
}
template <class T>
T Pow(T a, T b) {
  T ans = 1;
  T base = a;
  while (b) {
    if (b & 1) ans = (ans * base);
    base = (base * base);
    b /= 2;
  }
  return ans;
}
long long Bigmod(long long a, long long b) {
  long long res = 1;
  long long pw = a % 1000000007LL;
  while (b > 0) {
    if (b & 1) res = (res * pw) % 1000000007LL;
    pw = (pw * pw) % 1000000007LL;
    b /= 2;
  }
  return res;
}
int a_x[] = {1, -1, 0, 0};
int a_y[] = {0, 0, 1, -1};
long long X, Y;
void extend_euclid(long long a, long long b) {
  if (b == 0) {
    X = 1;
    Y = 0;
    return;
  }
  extend_euclid(b, a % b);
  long long x, y;
  x = Y;
  y = X - (a / b) * Y;
  X = x;
  Y = y;
}
long long inverse_modulo(long long a, long long b) {
  extend_euclid(a, b);
  return (X + 1000000007LL) % 1000000007LL;
}
int mn[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int n;
struct SegmentTree {
  vector<int> t;
  vector<int> add;
  int n;
  SegmentTree(int n_ = 0)
      : t(4 * n_ + 10, 1e9 + 10), add(4 * n_ + 10, 0), n(n_) {}
  void push(int i) {
    if (!add[i]) return;
    t[i] = add[i];
    if (2 * i + 2 < (int)t.size()) {
      add[2 * i + 1] = add[i];
      add[2 * i + 2] = add[i];
    }
    add[i] = 0;
  }
  void upd(int i, int tl, int tr, int l, int r, int x) {
    push(i);
    if (l == tl && r == tr) {
      add[i] = x;
      return;
    }
    int m = (tl + tr) / 2;
    if (l <= m) upd(2 * i + 1, tl, m, l, min(r, m), x);
    if (r > m) upd(2 * i + 2, m + 1, tr, max(m + 1, l), r, x);
    push(2 * i + 1);
    push(2 * i + 2);
    t[i] = min(t[2 * i + 1], t[2 * i + 2]);
  }
  void upd(int l, int r, int x) { upd(0, 0, n - 1, l, r, x); }
  int get(int i, int tl, int tr, int l, int r) {
    push(i);
    if (l <= tl && tr <= r) return t[i];
    int ml = 1e9 + 10;
    int mr = 1e9 + 10;
    int m = (tl + tr) / 2;
    if (l <= m) ml = get(2 * i + 1, tl, m, l, r);
    if (r > m) mr = get(2 * i + 2, m + 1, tr, l, r);
    return min(ml, mr);
  }
  int get(int l, int r) { return get(0, 0, n - 1, l, r); }
};
SegmentTree tree1;
int get_init(int l, int r) {
  if (r - l + 1 >= n) {
    return tree1.get(0, n - 1);
  }
  l %= n;
  r %= n;
  if (r < l) r += n;
  return tree1.get(l, r);
}
int l[100005];
int r[100005];
int x[100005];
int type[100005];
int a[100005];
int main() {
  int k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  tree1 = SegmentTree(2 * n);
  for (int i = 0; i < 2 * n; i++) {
    tree1.upd(i, i, a[i % n]);
  }
  vector<int> lst;
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d", &type[i]);
    scanf("%d %d", &l[i], &r[i]);
    l[i]--;
    r[i]--;
    if (type[i] == 1) scanf("%d", &x[i]);
    lst.push_back(l[i]);
    lst.push_back(r[i] + 1);
  }
  sort(lst.begin(), lst.end());
  lst.resize(unique(lst.begin(), lst.end()) - lst.begin());
  SegmentTree tree2(lst.size());
  for (int i = 0; i < lst.size() - 1; i++) {
    tree2.upd(i, i, get_init(lst[i], lst[i + 1] - 1));
  }
  for (int i = 0; i < q; i++) {
    int L = lower_bound(lst.begin(), lst.end(), l[i]) - lst.begin();
    int R = lower_bound(lst.begin(), lst.end(), r[i] + 1) - lst.begin() - 1;
    if (type[i] == 1)
      tree2.upd(L, R, x[i]);
    else
      printf("%d\n", tree2.get(L, R));
  }
  return 0;
}

### Prompt

Construct a CPP code solution to the problem outlined:

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 <class T>
T Bitcnt(T a) {
  int sum = 0;
  while (a) {
    if (a & 1) sum++;
    a /= 2;
  }
  return sum;
}
template <class T>
T Max3(T a, T b, T c) {
  return max(a, max(b, c));
}
template <class T>
T Lcm(T a, T b) {
  T tmp = __gcd(a, b);
  return (a / tmp) * b;
}
template <class T>
T Pow(T a, T b) {
  T ans = 1;
  T base = a;
  while (b) {
    if (b & 1) ans = (ans * base);
    base = (base * base);
    b /= 2;
  }
  return ans;
}
long long Bigmod(long long a, long long b) {
  long long res = 1;
  long long pw = a % 1000000007LL;
  while (b > 0) {
    if (b & 1) res = (res * pw) % 1000000007LL;
    pw = (pw * pw) % 1000000007LL;
    b /= 2;
  }
  return res;
}
int a_x[] = {1, -1, 0, 0};
int a_y[] = {0, 0, 1, -1};
long long X, Y;
void extend_euclid(long long a, long long b) {
  if (b == 0) {
    X = 1;
    Y = 0;
    return;
  }
  extend_euclid(b, a % b);
  long long x, y;
  x = Y;
  y = X - (a / b) * Y;
  X = x;
  Y = y;
}
long long inverse_modulo(long long a, long long b) {
  extend_euclid(a, b);
  return (X + 1000000007LL) % 1000000007LL;
}
int mn[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int n;
struct SegmentTree {
  vector<int> t;
  vector<int> add;
  int n;
  SegmentTree(int n_ = 0)
      : t(4 * n_ + 10, 1e9 + 10), add(4 * n_ + 10, 0), n(n_) {}
  void push(int i) {
    if (!add[i]) return;
    t[i] = add[i];
    if (2 * i + 2 < (int)t.size()) {
      add[2 * i + 1] = add[i];
      add[2 * i + 2] = add[i];
    }
    add[i] = 0;
  }
  void upd(int i, int tl, int tr, int l, int r, int x) {
    push(i);
    if (l == tl && r == tr) {
      add[i] = x;
      return;
    }
    int m = (tl + tr) / 2;
    if (l <= m) upd(2 * i + 1, tl, m, l, min(r, m), x);
    if (r > m) upd(2 * i + 2, m + 1, tr, max(m + 1, l), r, x);
    push(2 * i + 1);
    push(2 * i + 2);
    t[i] = min(t[2 * i + 1], t[2 * i + 2]);
  }
  void upd(int l, int r, int x) { upd(0, 0, n - 1, l, r, x); }
  int get(int i, int tl, int tr, int l, int r) {
    push(i);
    if (l <= tl && tr <= r) return t[i];
    int ml = 1e9 + 10;
    int mr = 1e9 + 10;
    int m = (tl + tr) / 2;
    if (l <= m) ml = get(2 * i + 1, tl, m, l, r);
    if (r > m) mr = get(2 * i + 2, m + 1, tr, l, r);
    return min(ml, mr);
  }
  int get(int l, int r) { return get(0, 0, n - 1, l, r); }
};
SegmentTree tree1;
int get_init(int l, int r) {
  if (r - l + 1 >= n) {
    return tree1.get(0, n - 1);
  }
  l %= n;
  r %= n;
  if (r < l) r += n;
  return tree1.get(l, r);
}
int l[100005];
int r[100005];
int x[100005];
int type[100005];
int a[100005];
int main() {
  int k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  tree1 = SegmentTree(2 * n);
  for (int i = 0; i < 2 * n; i++) {
    tree1.upd(i, i, a[i % n]);
  }
  vector<int> lst;
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d", &type[i]);
    scanf("%d %d", &l[i], &r[i]);
    l[i]--;
    r[i]--;
    if (type[i] == 1) scanf("%d", &x[i]);
    lst.push_back(l[i]);
    lst.push_back(r[i] + 1);
  }
  sort(lst.begin(), lst.end());
  lst.resize(unique(lst.begin(), lst.end()) - lst.begin());
  SegmentTree tree2(lst.size());
  for (int i = 0; i < lst.size() - 1; i++) {
    tree2.upd(i, i, get_init(lst[i], lst[i + 1] - 1));
  }
  for (int i = 0; i < q; i++) {
    int L = lower_bound(lst.begin(), lst.end(), l[i]) - lst.begin();
    int R = lower_bound(lst.begin(), lst.end(), r[i] + 1) - lst.begin() - 1;
    if (type[i] == 1)
      tree2.upd(L, R, x[i]);
    else
      printf("%d\n", tree2.get(L, R));
  }
  return 0;
}

```