#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
struct RMQ {
  int lvl(int x) { return 31 - __builtin_clz(x); }
  vector<vector<int>> spr;
  RMQ() {}
  RMQ(vector<int> &v) {
    spr.push_back(v);
    for (int j = 1; (1 << j) <= (int)v.size(); ++j) {
      spr.push_back(vector<int>(v.size() - (1 << j) + 1));
      for (int i = 0; i < (int)spr[j].size(); ++i) {
        spr[j][i] = min(spr[j - 1][i], spr[j - 1][i + (1 << (j - 1))]);
      }
    }
  }
  int get(int l, int r) {
    int d = lvl(r - l + 1);
    return min(spr[d][l], spr[d][r - (1 << d) + 1]);
  }
};
RMQ K;
int n, k;
int get_minimum(int l, int r) {
  if (r - l + 1 >= n) return K.get(0, n - 1);
  l %= n;
  r %= n;
  if (l <= r) return K.get(l, r);
  return min(K.get(0, r), K.get(l, n - 1));
}
struct node {
  node *l = 0, *r = 0;
  int mi = -1, setmi = -1;
  int get(int L, int R) {
    if (mi != -1) return mi;
    return get_minimum(L, R);
  }
};
node *left(node *x) {
  if (!x->l) x->l = new node();
  return x->l;
}
node *right(node *x) {
  if (!x->r) x->r = new node();
  return x->r;
}
void push(node *x) {
  if (x->setmi == -1) return;
  left(x)->setmi = x->setmi;
  right(x)->setmi = x->setmi;
  left(x)->mi = x->setmi;
  right(x)->mi = x->setmi;
  x->setmi = -1;
}
int query(node *x, int l, int r, int L, int R) {
  if (R < l || r < L) return inf;
  if (L <= l && r <= R) return x->get(l, r);
  push(x);
  return min(query(left(x), l, (l + r) / 2, L, R),
             query(right(x), (l + r) / 2 + 1, r, L, R));
}
void modify(node *x, int l, int r, int L, int R, int y) {
  if (R < l || r < L) return;
  if (L <= l && r <= R) {
    x->setmi = y;
    x->mi = y;
  } else {
    push(x);
    modify(left(x), l, (l + r) / 2, L, R, y);
    modify(right(x), (l + r) / 2 + 1, r, L, R, y);
    x->mi = min(x->l->get(l, (l + r) / 2), x->r->get((l + r) / 2 + 1, r));
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> k;
  vector<int> v(n);
  for (int i = 0; i < n; ++i) cin >> v[i];
  K = RMQ(v);
  node *seg = new node();
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int t, l, r, x;
    cin >> t;
    if (t == 1) {
      cin >> l >> r >> x;
      --l;
      --r;
      modify(seg, 0, n * k - 1, l, r, x);
    } else {
      cin >> l >> r;
      --l;
      --r;
      cout << query(seg, 0, n * k - 1, l, r) << '\n';
    }
  }
}

### Prompt

Please create a solution in CPP 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;
struct RMQ {
  int lvl(int x) { return 31 - __builtin_clz(x); }
  vector<vector<int>> spr;
  RMQ() {}
  RMQ(vector<int> &v) {
    spr.push_back(v);
    for (int j = 1; (1 << j) <= (int)v.size(); ++j) {
      spr.push_back(vector<int>(v.size() - (1 << j) + 1));
      for (int i = 0; i < (int)spr[j].size(); ++i) {
        spr[j][i] = min(spr[j - 1][i], spr[j - 1][i + (1 << (j - 1))]);
      }
    }
  }
  int get(int l, int r) {
    int d = lvl(r - l + 1);
    return min(spr[d][l], spr[d][r - (1 << d) + 1]);
  }
};
RMQ K;
int n, k;
int get_minimum(int l, int r) {
  if (r - l + 1 >= n) return K.get(0, n - 1);
  l %= n;
  r %= n;
  if (l <= r) return K.get(l, r);
  return min(K.get(0, r), K.get(l, n - 1));
}
struct node {
  node *l = 0, *r = 0;
  int mi = -1, setmi = -1;
  int get(int L, int R) {
    if (mi != -1) return mi;
    return get_minimum(L, R);
  }
};
node *left(node *x) {
  if (!x->l) x->l = new node();
  return x->l;
}
node *right(node *x) {
  if (!x->r) x->r = new node();
  return x->r;
}
void push(node *x) {
  if (x->setmi == -1) return;
  left(x)->setmi = x->setmi;
  right(x)->setmi = x->setmi;
  left(x)->mi = x->setmi;
  right(x)->mi = x->setmi;
  x->setmi = -1;
}
int query(node *x, int l, int r, int L, int R) {
  if (R < l || r < L) return inf;
  if (L <= l && r <= R) return x->get(l, r);
  push(x);
  return min(query(left(x), l, (l + r) / 2, L, R),
             query(right(x), (l + r) / 2 + 1, r, L, R));
}
void modify(node *x, int l, int r, int L, int R, int y) {
  if (R < l || r < L) return;
  if (L <= l && r <= R) {
    x->setmi = y;
    x->mi = y;
  } else {
    push(x);
    modify(left(x), l, (l + r) / 2, L, R, y);
    modify(right(x), (l + r) / 2 + 1, r, L, R, y);
    x->mi = min(x->l->get(l, (l + r) / 2), x->r->get((l + r) / 2 + 1, r));
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> k;
  vector<int> v(n);
  for (int i = 0; i < n; ++i) cin >> v[i];
  K = RMQ(v);
  node *seg = new node();
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int t, l, r, x;
    cin >> t;
    if (t == 1) {
      cin >> l >> r >> x;
      --l;
      --r;
      modify(seg, 0, n * k - 1, l, r, x);
    } else {
      cin >> l >> r;
      --l;
      --r;
      cout << query(seg, 0, n * k - 1, l, r) << '\n';
    }
  }
}

```