#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 10, maxN = 1e5 + 10;
struct TNode {
  TNode *lef, *rig;
  int l, r, val, lazy;
  TNode() {
    l = r = val = lazy = 0;
    lef = rig = nullptr;
  }
  void set(int le, int ri) {
    l = le;
    r = ri;
    val = INF;
    lazy = 0;
    lef = rig = nullptr;
  }
} * root, *base;
int n, k, q, a[maxN];
void Down(TNode *par) {
  par->lef->val = par->lef->lazy = par->lazy;
  par->rig->val = par->rig->lazy = par->lazy;
  par->lazy = 0;
}
int Get(TNode *par, int u, int v);
int GetFromBase(int u, int v) {
  int su = (u + n - 1) / n, sv = (v + n - 1) / n;
  int iu = u % n, iv = v % n;
  if (!iu) iu = n;
  if (!iv) iv = n;
  if (su == sv) return Get(base, iu, iv);
  if (su + 1 == sv) return min(Get(base, iu, n), Get(base, 1, iv));
  return base->val;
}
void Update(TNode *par, int u, int v, int val) {
  int l = par->l, r = par->r;
  if (v < l || r < u) return;
  if (u <= l && r <= v) {
    par->val = val;
    par->lazy = val;
    return;
  }
  int mid = l + r >> 1;
  if (par->lef == nullptr) {
    par->lef = new TNode();
    par->lef->set(l, mid);
    par->lef->val = GetFromBase(l, mid);
  }
  if (par->rig == nullptr) {
    par->rig = new TNode();
    par->rig->set(mid + 1, r);
    par->rig->val = GetFromBase(mid + 1, r);
  }
  if (par->lazy) Down(par);
  Update(par->lef, u, v, val);
  Update(par->rig, u, v, val);
  par->val = min(par->lef->val, par->rig->val);
}
int Get(TNode *par, int u, int v) {
  int l = par->l, r = par->r;
  if (v < l || r < u) return INF;
  if (u <= l && r <= v) return par->val;
  int mid = l + r >> 1;
  if (par->lef == nullptr) {
    par->lef = new TNode();
    par->lef->set(l, mid);
    par->lef->val = GetFromBase(l, mid);
  }
  if (par->rig == nullptr) {
    par->rig = new TNode();
    par->rig->set(mid + 1, r);
    par->rig->val = GetFromBase(mid + 1, r);
  }
  if (par->lazy) Down(par);
  return min(Get(par->lef, u, v), Get(par->rig, u, v));
}
void Build(TNode *par) {
  int l = par->l, r = par->r;
  if (l == r) {
    par->val = a[l];
    return;
  }
  int mid = l + r >> 1;
  par->lef = new TNode();
  par->lef->set(l, mid);
  par->rig = new TNode();
  par->rig->set(mid + 1, r);
  Build(par->lef);
  Build(par->rig);
  par->val = min(par->lef->val, par->rig->val);
}
int main() {
  scanf("%d%d", &n, &k);
  root = new TNode();
  root->set(1, n * k);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  base = new TNode();
  base->set(1, n);
  Build(base);
  for (int i = 1; i <= n; ++i) Update(root, i, i, a[i]);
  scanf("%d", &q);
  for (int i = 1; i <= q; ++i) {
    int t, l, r, x;
    scanf("%d%d%d", &t, &l, &r);
    if (t == 1) {
      scanf("%d", &x);
      Update(root, l, r, x);
    } else
      printf("%d\n", Get(root, l, r));
  }
}

### Prompt

Please formulate 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>
using namespace std;
const int INF = 1e9 + 10, maxN = 1e5 + 10;
struct TNode {
  TNode *lef, *rig;
  int l, r, val, lazy;
  TNode() {
    l = r = val = lazy = 0;
    lef = rig = nullptr;
  }
  void set(int le, int ri) {
    l = le;
    r = ri;
    val = INF;
    lazy = 0;
    lef = rig = nullptr;
  }
} * root, *base;
int n, k, q, a[maxN];
void Down(TNode *par) {
  par->lef->val = par->lef->lazy = par->lazy;
  par->rig->val = par->rig->lazy = par->lazy;
  par->lazy = 0;
}
int Get(TNode *par, int u, int v);
int GetFromBase(int u, int v) {
  int su = (u + n - 1) / n, sv = (v + n - 1) / n;
  int iu = u % n, iv = v % n;
  if (!iu) iu = n;
  if (!iv) iv = n;
  if (su == sv) return Get(base, iu, iv);
  if (su + 1 == sv) return min(Get(base, iu, n), Get(base, 1, iv));
  return base->val;
}
void Update(TNode *par, int u, int v, int val) {
  int l = par->l, r = par->r;
  if (v < l || r < u) return;
  if (u <= l && r <= v) {
    par->val = val;
    par->lazy = val;
    return;
  }
  int mid = l + r >> 1;
  if (par->lef == nullptr) {
    par->lef = new TNode();
    par->lef->set(l, mid);
    par->lef->val = GetFromBase(l, mid);
  }
  if (par->rig == nullptr) {
    par->rig = new TNode();
    par->rig->set(mid + 1, r);
    par->rig->val = GetFromBase(mid + 1, r);
  }
  if (par->lazy) Down(par);
  Update(par->lef, u, v, val);
  Update(par->rig, u, v, val);
  par->val = min(par->lef->val, par->rig->val);
}
int Get(TNode *par, int u, int v) {
  int l = par->l, r = par->r;
  if (v < l || r < u) return INF;
  if (u <= l && r <= v) return par->val;
  int mid = l + r >> 1;
  if (par->lef == nullptr) {
    par->lef = new TNode();
    par->lef->set(l, mid);
    par->lef->val = GetFromBase(l, mid);
  }
  if (par->rig == nullptr) {
    par->rig = new TNode();
    par->rig->set(mid + 1, r);
    par->rig->val = GetFromBase(mid + 1, r);
  }
  if (par->lazy) Down(par);
  return min(Get(par->lef, u, v), Get(par->rig, u, v));
}
void Build(TNode *par) {
  int l = par->l, r = par->r;
  if (l == r) {
    par->val = a[l];
    return;
  }
  int mid = l + r >> 1;
  par->lef = new TNode();
  par->lef->set(l, mid);
  par->rig = new TNode();
  par->rig->set(mid + 1, r);
  Build(par->lef);
  Build(par->rig);
  par->val = min(par->lef->val, par->rig->val);
}
int main() {
  scanf("%d%d", &n, &k);
  root = new TNode();
  root->set(1, n * k);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  base = new TNode();
  base->set(1, n);
  Build(base);
  for (int i = 1; i <= n; ++i) Update(root, i, i, a[i]);
  scanf("%d", &q);
  for (int i = 1; i <= q; ++i) {
    int t, l, r, x;
    scanf("%d%d%d", &t, &l, &r);
    if (t == 1) {
      scanf("%d", &x);
      Update(root, l, r, x);
    } else
      printf("%d\n", Get(root, l, r));
  }
}

```