#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool uax(T &x, T y) {
  return (y > x) ? x = y, true : false;
}
template <typename T>
inline bool uin(T &x, T y) {
  return (y < x) ? x = y, true : false;
}
string to_string(char c) { return "'" + string(1, c) + "'"; }
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
template <typename A>
string to_string(A);
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool f = false;
  string r = "{";
  for (auto x : v) {
    if (f) r += ", ";
    r += to_string(x);
    f = true;
  }
  return r += "}";
}
template <typename A>
string to_string(vector<vector<A>> v) {
  string r;
  for (auto x : v) r += "\n" + to_string(x);
  return r;
}
int Nerr;
template <typename A>
string to_string(A *p) {
  return to_string(vector<A>(p, p + Nerr));
}
void err(istream_iterator<string>) { cerr << endl; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << to_string(a) << "; ";
  err(++it, args...);
}
template <typename T>
void kek(T ans) {
  cout << ans << endl;
  exit(0);
}
int const MOD = 1e9 + 7;
long long const INF = 1e18 + 42;
const int N = 1e5 + 42;
int a[N << 1];
int n, k;
int qmin(int l, int r) {
  int res = MOD;
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) uin(res, a[l++]);
    if (r & 1) uin(res, a[--r]);
  }
  return res;
}
struct Node;
struct Node {
  shared_ptr<Node> l, r;
  int L, R, val, tag;
  Node(int ll, int rr) : L(ll), R(rr), val(MOD), tag() {
    if (R - L >= n) {
      val = a[1];
    } else {
      ll = L % n, rr = R % n;
      if (ll < rr)
        val = qmin(ll, rr);
      else if (ll > rr)
        val = min(qmin(ll, n), qmin(0, rr));
    }
  }
  void put(int ll, int rr, int x) {
    if (ll <= L and R <= rr) {
      tag = x, push();
      return;
    }
    push();
    if (ll >= R or rr <= L) return;
    int M = (L + R) >> 1;
    if (!l) l = make_shared<Node>(L, M);
    if (!r) r = make_shared<Node>(M, R);
    l->put(ll, rr, x);
    r->put(ll, rr, x);
    val = min(l->val, r->val);
  }
  int ask(int ll, int rr) {
    push();
    if (ll >= R or rr <= L) return MOD;
    if (ll <= L and R <= rr) return val;
    int M = (L + R) >> 1;
    if (!l) l = make_shared<Node>(L, M);
    if (!r) r = make_shared<Node>(M, R);
    return min(l->ask(ll, rr), r->ask(ll, rr));
  }
  void push() {
    if (!tag) return;
    int M = (L + R) >> 1;
    if (!l) l = make_shared<Node>(L, M);
    if (!r) r = make_shared<Node>(M, R);
    val = l->tag = r->tag = tag;
    tag = 0;
  }
};
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> a[i + n];
  }
  for (int i = n - 1; i > 0; --i) {
    a[i] = min(a[i << 1], a[i << 1 | 1]);
  }
  Node root(0, n * k);
  int q;
  cin >> q;
  while (q--) {
    int t;
    cin >> t;
    if (t == 1) {
      int l, r, x;
      cin >> l >> r >> x;
      --l;
      root.put(l, r, x);
    } else {
      int l, r;
      cin >> l >> r;
      --l;
      cout << root.ask(l, r) << '\n';
    }
  }
}

### Prompt

Create a solution in CPP for 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;
template <typename T>
inline bool uax(T &x, T y) {
  return (y > x) ? x = y, true : false;
}
template <typename T>
inline bool uin(T &x, T y) {
  return (y < x) ? x = y, true : false;
}
string to_string(char c) { return "'" + string(1, c) + "'"; }
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
template <typename A>
string to_string(A);
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool f = false;
  string r = "{";
  for (auto x : v) {
    if (f) r += ", ";
    r += to_string(x);
    f = true;
  }
  return r += "}";
}
template <typename A>
string to_string(vector<vector<A>> v) {
  string r;
  for (auto x : v) r += "\n" + to_string(x);
  return r;
}
int Nerr;
template <typename A>
string to_string(A *p) {
  return to_string(vector<A>(p, p + Nerr));
}
void err(istream_iterator<string>) { cerr << endl; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << to_string(a) << "; ";
  err(++it, args...);
}
template <typename T>
void kek(T ans) {
  cout << ans << endl;
  exit(0);
}
int const MOD = 1e9 + 7;
long long const INF = 1e18 + 42;
const int N = 1e5 + 42;
int a[N << 1];
int n, k;
int qmin(int l, int r) {
  int res = MOD;
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) uin(res, a[l++]);
    if (r & 1) uin(res, a[--r]);
  }
  return res;
}
struct Node;
struct Node {
  shared_ptr<Node> l, r;
  int L, R, val, tag;
  Node(int ll, int rr) : L(ll), R(rr), val(MOD), tag() {
    if (R - L >= n) {
      val = a[1];
    } else {
      ll = L % n, rr = R % n;
      if (ll < rr)
        val = qmin(ll, rr);
      else if (ll > rr)
        val = min(qmin(ll, n), qmin(0, rr));
    }
  }
  void put(int ll, int rr, int x) {
    if (ll <= L and R <= rr) {
      tag = x, push();
      return;
    }
    push();
    if (ll >= R or rr <= L) return;
    int M = (L + R) >> 1;
    if (!l) l = make_shared<Node>(L, M);
    if (!r) r = make_shared<Node>(M, R);
    l->put(ll, rr, x);
    r->put(ll, rr, x);
    val = min(l->val, r->val);
  }
  int ask(int ll, int rr) {
    push();
    if (ll >= R or rr <= L) return MOD;
    if (ll <= L and R <= rr) return val;
    int M = (L + R) >> 1;
    if (!l) l = make_shared<Node>(L, M);
    if (!r) r = make_shared<Node>(M, R);
    return min(l->ask(ll, rr), r->ask(ll, rr));
  }
  void push() {
    if (!tag) return;
    int M = (L + R) >> 1;
    if (!l) l = make_shared<Node>(L, M);
    if (!r) r = make_shared<Node>(M, R);
    val = l->tag = r->tag = tag;
    tag = 0;
  }
};
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> a[i + n];
  }
  for (int i = n - 1; i > 0; --i) {
    a[i] = min(a[i << 1], a[i << 1 | 1]);
  }
  Node root(0, n * k);
  int q;
  cin >> q;
  while (q--) {
    int t;
    cin >> t;
    if (t == 1) {
      int l, r, x;
      cin >> l >> r >> x;
      --l;
      root.put(l, r, x);
    } else {
      int l, r;
      cin >> l >> r;
      --l;
      cout << root.ask(l, r) << '\n';
    }
  }
}

```