#include <bits/stdc++.h>
const int N = 1e5 + 1, INF = 1e9 + 7;
int n, k, b[N], f[30][N];
struct TNode {
  int l, r, lz, res;
  TNode *lc, *rc;
  TNode(int _l, int _r) : l(_l), r(_r), lz(), lc(), rc() {
    int k = 31 - __builtin_clz(r - l + 1);
    res = std::min(f[k][(l - 1) % n + 1], f[k][(r - (1 << k) + 1 - 1) % n + 1]);
  }
};
TNode* root;
void build_rmq() {
  for (int i = 1; i <= n; ++i) f[0][(i - 1) % n + 1] = b[i];
  for (int i = 0; 1 << i < n * k; ++i)
    for (int j = 1; j <= n; ++j)
      f[i + 1][(j - 1) % n + 1] =
          std::min(f[i][(j - 1) % n + 1], f[i][(j + (1 << i) - 1) % n + 1]);
}
void modify(int x, TNode* n) { n->res = n->lz = x; }
void lazy(TNode* n) {
  int mid = (n->l + n->r) / 2;
  if (n->lc == nullptr) n->lc = new TNode(n->l, mid);
  if (n->rc == nullptr) n->rc = new TNode(mid + 1, n->r);
  if (n->lz == 0) return;
  modify(n->lz, n->lc);
  modify(n->lz, n->rc);
  n->lz = 0;
}
void refresh(TNode* n) { n->res = std::min(n->lc->res, n->rc->res); }
void update(int l, int r, int x, TNode* n = root) {
  if (n->r < l || r < n->l) return;
  if (l <= n->l && n->r <= r) {
    modify(x, n);
    return;
  }
  lazy(n);
  update(l, r, x, n->lc);
  update(l, r, x, n->rc);
  refresh(n);
}
int query(int l, int r, TNode* n = root) {
  if (n->r < l || r < n->l) return INF;
  if (l <= n->l && n->r <= r) return n->res;
  lazy(n);
  return std::min(query(l, r, n->lc), query(l, r, n->rc));
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) scanf("%d", &b[i]);
  build_rmq();
  root = new TNode(1, n * k);
  int q;
  scanf("%d", &q);
  for (int i = 1; i <= q; ++i) {
    int t;
    scanf("%d", &t);
    switch (t) {
      case 1: {
        int l, r, x;
        scanf("%d%d%d", &l, &r, &x);
        update(l, r, x);
        break;
      }
      case 2: {
        int l, r;
        scanf("%d%d", &l, &r);
        printf("%d\n", query(l, r));
        break;
      }
    }
  }
  return 0;
}

### Prompt

Your challenge is to write 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>
const int N = 1e5 + 1, INF = 1e9 + 7;
int n, k, b[N], f[30][N];
struct TNode {
  int l, r, lz, res;
  TNode *lc, *rc;
  TNode(int _l, int _r) : l(_l), r(_r), lz(), lc(), rc() {
    int k = 31 - __builtin_clz(r - l + 1);
    res = std::min(f[k][(l - 1) % n + 1], f[k][(r - (1 << k) + 1 - 1) % n + 1]);
  }
};
TNode* root;
void build_rmq() {
  for (int i = 1; i <= n; ++i) f[0][(i - 1) % n + 1] = b[i];
  for (int i = 0; 1 << i < n * k; ++i)
    for (int j = 1; j <= n; ++j)
      f[i + 1][(j - 1) % n + 1] =
          std::min(f[i][(j - 1) % n + 1], f[i][(j + (1 << i) - 1) % n + 1]);
}
void modify(int x, TNode* n) { n->res = n->lz = x; }
void lazy(TNode* n) {
  int mid = (n->l + n->r) / 2;
  if (n->lc == nullptr) n->lc = new TNode(n->l, mid);
  if (n->rc == nullptr) n->rc = new TNode(mid + 1, n->r);
  if (n->lz == 0) return;
  modify(n->lz, n->lc);
  modify(n->lz, n->rc);
  n->lz = 0;
}
void refresh(TNode* n) { n->res = std::min(n->lc->res, n->rc->res); }
void update(int l, int r, int x, TNode* n = root) {
  if (n->r < l || r < n->l) return;
  if (l <= n->l && n->r <= r) {
    modify(x, n);
    return;
  }
  lazy(n);
  update(l, r, x, n->lc);
  update(l, r, x, n->rc);
  refresh(n);
}
int query(int l, int r, TNode* n = root) {
  if (n->r < l || r < n->l) return INF;
  if (l <= n->l && n->r <= r) return n->res;
  lazy(n);
  return std::min(query(l, r, n->lc), query(l, r, n->rc));
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) scanf("%d", &b[i]);
  build_rmq();
  root = new TNode(1, n * k);
  int q;
  scanf("%d", &q);
  for (int i = 1; i <= q; ++i) {
    int t;
    scanf("%d", &t);
    switch (t) {
      case 1: {
        int l, r, x;
        scanf("%d%d%d", &l, &r, &x);
        update(l, r, x);
        break;
      }
      case 2: {
        int l, r;
        scanf("%d%d", &l, &r);
        printf("%d\n", query(l, r));
        break;
      }
    }
  }
  return 0;
}

```