#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 3;
const int inf = 1e9 + 7;
int a[N << 1], k, n, sp[N << 1][18];
void BuildRMQ() {
  for (int i = 0; i < (n << 1); ++i) sp[i][0] = a[i];
  for (int x = 1; (1 << x) <= (n << 1); ++x) {
    for (int i = 0; i + (1 << x) - 1 < (n << 1); ++i)
      sp[i][x] = min(sp[i][x - 1], sp[i + (1 << (x - 1))][x - 1]);
  }
}
int Query(int l, int r) {
  int k = (int)31 - __builtin_clz(r - l + 1);
  return min(sp[l][k], sp[r - (1 << k) + 1][k]);
}
struct Node {
  struct Node *l, *r;
  int val, lazy;
  Node(int ll, int rr) : l(NULL), r(NULL), lazy(-1) {
    if (rr - ll + 1 >= n) {
      val = Query(0, n - 1);
    } else {
      if (ll == rr) {
        ll %= n;
        rr %= n;
        val = a[ll];
      } else {
        ll %= n;
        rr %= n;
        if (rr < ll) rr += n;
        val = Query(ll, rr);
      }
    }
  }
};
void Push(Node *id, int ll, int rr) {
  if (id->lazy != -1) {
    int t = id->lazy;
    Node *x = id->l;
    Node *y = id->r;
    x->val = t;
    x->lazy = t;
    y->val = t;
    y->lazy = t;
    id->lazy = -1;
  }
}
int Get(Node *id, int l, int r, int u, int v) {
  if (r < u || v < l) return inf;
  if (u <= l && r <= v) {
    return id->val;
  }
  int mid = (l + r) / 2;
  if (id->l == NULL) id->l = new Node(l, mid);
  if (id->r == NULL) id->r = new Node(mid + 1, r);
  Push(id, l, r);
  return min(Get(id->l, l, mid, u, v), Get(id->r, mid + 1, r, u, v));
}
void Update(Node *id, int l, int r, int u, int v, int val) {
  if (r < u || v < l) {
    return;
  }
  if (u <= l && r <= v) {
    id->val = val;
    id->lazy = val;
    return;
  }
  int mid = (l + r) / 2;
  if (id->l == NULL) id->l = new Node(l, mid);
  if (id->r == NULL) id->r = new Node(mid + 1, r);
  Push(id, l, r);
  Update(id->l, l, mid, u, v, val);
  Update(id->r, mid + 1, r, u, v, val);
  id->val = min(id->l->val, id->r->val);
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    a[n + i] = a[i];
  }
  BuildRMQ();
  Node *tree = new Node(0, n * k - 1);
  int q;
  scanf("%d", &q);
  while (q--) {
    int t, l, r;
    scanf("%d%d%d", &t, &l, &r);
    r--, l--;
    if (t == 1) {
      int x;
      scanf("%d", &x);
      Update(tree, 0, n * k - 1, l, r, x);
    } else {
      printf("%d\n", Get(tree, 0, n * k - 1, l, r));
    }
  }
  return 0;
}

### Prompt

In Cpp, your task is to solve 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 + 3;
const int inf = 1e9 + 7;
int a[N << 1], k, n, sp[N << 1][18];
void BuildRMQ() {
  for (int i = 0; i < (n << 1); ++i) sp[i][0] = a[i];
  for (int x = 1; (1 << x) <= (n << 1); ++x) {
    for (int i = 0; i + (1 << x) - 1 < (n << 1); ++i)
      sp[i][x] = min(sp[i][x - 1], sp[i + (1 << (x - 1))][x - 1]);
  }
}
int Query(int l, int r) {
  int k = (int)31 - __builtin_clz(r - l + 1);
  return min(sp[l][k], sp[r - (1 << k) + 1][k]);
}
struct Node {
  struct Node *l, *r;
  int val, lazy;
  Node(int ll, int rr) : l(NULL), r(NULL), lazy(-1) {
    if (rr - ll + 1 >= n) {
      val = Query(0, n - 1);
    } else {
      if (ll == rr) {
        ll %= n;
        rr %= n;
        val = a[ll];
      } else {
        ll %= n;
        rr %= n;
        if (rr < ll) rr += n;
        val = Query(ll, rr);
      }
    }
  }
};
void Push(Node *id, int ll, int rr) {
  if (id->lazy != -1) {
    int t = id->lazy;
    Node *x = id->l;
    Node *y = id->r;
    x->val = t;
    x->lazy = t;
    y->val = t;
    y->lazy = t;
    id->lazy = -1;
  }
}
int Get(Node *id, int l, int r, int u, int v) {
  if (r < u || v < l) return inf;
  if (u <= l && r <= v) {
    return id->val;
  }
  int mid = (l + r) / 2;
  if (id->l == NULL) id->l = new Node(l, mid);
  if (id->r == NULL) id->r = new Node(mid + 1, r);
  Push(id, l, r);
  return min(Get(id->l, l, mid, u, v), Get(id->r, mid + 1, r, u, v));
}
void Update(Node *id, int l, int r, int u, int v, int val) {
  if (r < u || v < l) {
    return;
  }
  if (u <= l && r <= v) {
    id->val = val;
    id->lazy = val;
    return;
  }
  int mid = (l + r) / 2;
  if (id->l == NULL) id->l = new Node(l, mid);
  if (id->r == NULL) id->r = new Node(mid + 1, r);
  Push(id, l, r);
  Update(id->l, l, mid, u, v, val);
  Update(id->r, mid + 1, r, u, v, val);
  id->val = min(id->l->val, id->r->val);
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    a[n + i] = a[i];
  }
  BuildRMQ();
  Node *tree = new Node(0, n * k - 1);
  int q;
  scanf("%d", &q);
  while (q--) {
    int t, l, r;
    scanf("%d%d%d", &t, &l, &r);
    r--, l--;
    if (t == 1) {
      int x;
      scanf("%d", &x);
      Update(tree, 0, n * k - 1, l, r, x);
    } else {
      printf("%d\n", Get(tree, 0, n * k - 1, l, r));
    }
  }
  return 0;
}

```