#include <bits/stdc++.h>
using namespace std;
const int N = 200009;
const int LG2 = 18;
const int oo = (int)(1e9) + 9;
int n, k, query;
int Pow[19];
int a[N], v[N], type[N];
vector<int> b;
pair<int, int> q[N];
map<int, int> M;
int RMQ[N * 2][20];
int vmin;
int m;
int f[N];
int IT[N * 4];
int zip[N * 4];
vector<pair<int, int> > c;
int getMin(int i, int j) {
  int k = floor(log2((double)(j - i + 1)));
  return min(RMQ[j][k], RMQ[i + Pow[k] - 1][k]);
}
int cal(int l, int r) {
  if (r - l >= n) return vmin;
  l = (l - 1) % n + 1;
  r = (r - 1) % n + 1;
  if (l <= r) {
    return getMin(l, r);
  }
  return getMin(l, r + n);
}
void build(int i, int l, int r) {
  if (l > r) return;
  if (l == r) {
    IT[i] = cal(b[l - 1], b[l] - 1);
    return;
  }
  int mid = (l + r) >> 1;
  build(i << 1, l, mid);
  build((i << 1) + 1, mid + 1, r);
  IT[i] = min(IT[i << 1], IT[(i << 1) + 1]);
}
void update(int i, int l, int r, int u, int v, int x) {
  if (l > r || l > v || r < u) return;
  if (l >= u && r <= v) {
    IT[i] = x;
    zip[i] = 1;
    return;
  }
  if (zip[i] == 1) {
    zip[i << 1] = zip[(i << 1) + 1] = 1;
    zip[i] = 0;
    IT[i << 1] = IT[(i << 1) + 1] = IT[i];
  }
  int mid = (l + r) >> 1;
  update(i << 1, l, mid, u, v, x);
  update((i << 1) + 1, mid + 1, r, u, v, x);
  IT[i] = min(IT[i << 1], IT[(i << 1) + 1]);
}
int get(int i, int l, int r, int u, int v) {
  if (l > r || l > v || r < u) return oo;
  if (l >= u && r <= v) return IT[i];
  if (zip[i] == 1) return IT[i];
  int mid = (l + r) >> 1;
  return min(get(i << 1, l, mid, u, v), get((i << 1) + 1, mid + 1, r, u, v));
}
void prepare() {
  vmin = oo;
  for (int i = 1; i <= n; i++) a[i + n] = a[i], vmin = min(vmin, a[i]);
  for (int i = 1; i <= n * 2; i++) RMQ[i][0] = a[i];
  Pow[0] = 1;
  for (int i = 1; i <= 18; i++) Pow[i] = Pow[i - 1] * 2;
  for (int j = 1; j < LG2; j++)
    for (int i = Pow[j]; i <= n * 2; i++)
      RMQ[i][j] = min(RMQ[i][j - 1], RMQ[i - Pow[j - 1]][j - 1]);
  m = b.size();
  build(1, 1, m - 1);
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  b.push_back(1);
  b.push_back(n * k + 1);
  scanf("%d", &query);
  for (int i = 1; i <= query; i++) {
    scanf("%d", &type[i]);
    if (type[i] == 1) {
      scanf("%d %d %d", &q[i].first, &q[i].second, &v[i]);
    } else {
      scanf("%d %d", &q[i].first, &q[i].second);
    }
    b.push_back(q[i].first);
    b.push_back(q[i].second + 1);
  }
  sort(b.begin(), b.end());
  vector<int>::iterator it = unique(b.begin(), b.end());
  b.resize(distance(b.begin(), it));
  sort(b.begin(), b.end());
  prepare();
  for (int i = 0; i <= m - 1; i++) M[b[i]] = i;
  for (int i = 1; i <= query; i++) {
    int l, r;
    l = M[q[i].first] + 1;
    r = M[q[i].second + 1];
    if (type[i] == 1) {
      update(1, 1, m - 1, l, r, v[i]);
    } else {
      printf("%d\n", get(1, 1, m - 1, l, r));
    }
  }
}

### 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>
using namespace std;
const int N = 200009;
const int LG2 = 18;
const int oo = (int)(1e9) + 9;
int n, k, query;
int Pow[19];
int a[N], v[N], type[N];
vector<int> b;
pair<int, int> q[N];
map<int, int> M;
int RMQ[N * 2][20];
int vmin;
int m;
int f[N];
int IT[N * 4];
int zip[N * 4];
vector<pair<int, int> > c;
int getMin(int i, int j) {
  int k = floor(log2((double)(j - i + 1)));
  return min(RMQ[j][k], RMQ[i + Pow[k] - 1][k]);
}
int cal(int l, int r) {
  if (r - l >= n) return vmin;
  l = (l - 1) % n + 1;
  r = (r - 1) % n + 1;
  if (l <= r) {
    return getMin(l, r);
  }
  return getMin(l, r + n);
}
void build(int i, int l, int r) {
  if (l > r) return;
  if (l == r) {
    IT[i] = cal(b[l - 1], b[l] - 1);
    return;
  }
  int mid = (l + r) >> 1;
  build(i << 1, l, mid);
  build((i << 1) + 1, mid + 1, r);
  IT[i] = min(IT[i << 1], IT[(i << 1) + 1]);
}
void update(int i, int l, int r, int u, int v, int x) {
  if (l > r || l > v || r < u) return;
  if (l >= u && r <= v) {
    IT[i] = x;
    zip[i] = 1;
    return;
  }
  if (zip[i] == 1) {
    zip[i << 1] = zip[(i << 1) + 1] = 1;
    zip[i] = 0;
    IT[i << 1] = IT[(i << 1) + 1] = IT[i];
  }
  int mid = (l + r) >> 1;
  update(i << 1, l, mid, u, v, x);
  update((i << 1) + 1, mid + 1, r, u, v, x);
  IT[i] = min(IT[i << 1], IT[(i << 1) + 1]);
}
int get(int i, int l, int r, int u, int v) {
  if (l > r || l > v || r < u) return oo;
  if (l >= u && r <= v) return IT[i];
  if (zip[i] == 1) return IT[i];
  int mid = (l + r) >> 1;
  return min(get(i << 1, l, mid, u, v), get((i << 1) + 1, mid + 1, r, u, v));
}
void prepare() {
  vmin = oo;
  for (int i = 1; i <= n; i++) a[i + n] = a[i], vmin = min(vmin, a[i]);
  for (int i = 1; i <= n * 2; i++) RMQ[i][0] = a[i];
  Pow[0] = 1;
  for (int i = 1; i <= 18; i++) Pow[i] = Pow[i - 1] * 2;
  for (int j = 1; j < LG2; j++)
    for (int i = Pow[j]; i <= n * 2; i++)
      RMQ[i][j] = min(RMQ[i][j - 1], RMQ[i - Pow[j - 1]][j - 1]);
  m = b.size();
  build(1, 1, m - 1);
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  b.push_back(1);
  b.push_back(n * k + 1);
  scanf("%d", &query);
  for (int i = 1; i <= query; i++) {
    scanf("%d", &type[i]);
    if (type[i] == 1) {
      scanf("%d %d %d", &q[i].first, &q[i].second, &v[i]);
    } else {
      scanf("%d %d", &q[i].first, &q[i].second);
    }
    b.push_back(q[i].first);
    b.push_back(q[i].second + 1);
  }
  sort(b.begin(), b.end());
  vector<int>::iterator it = unique(b.begin(), b.end());
  b.resize(distance(b.begin(), it));
  sort(b.begin(), b.end());
  prepare();
  for (int i = 0; i <= m - 1; i++) M[b[i]] = i;
  for (int i = 1; i <= query; i++) {
    int l, r;
    l = M[q[i].first] + 1;
    r = M[q[i].second + 1];
    if (type[i] == 1) {
      update(1, 1, m - 1, l, r, v[i]);
    } else {
      printf("%d\n", get(1, 1, m - 1, l, r));
    }
  }
}

```