#include <bits/stdc++.h>
using namespace std;
const int N = 300001;
int dp[N][19], n;
int query(int l, int r) {
  int m = log2(r - l + 1);
  return min(dp[l][m], dp[r - (1 << m) + 1][m]);
}
int Q(int L, int R) {
  if (R - L + 1 >= n) return query(0, n - 1);
  L %= n;
  R %= n;
  if (L > R) {
    return min(query(L, n - 1), query(0, R));
  }
  return query(L, R);
}
struct node {
  int value, lazy;
  node *l, *r;
  node(int L, int R) {
    l = r = nullptr;
    value = Q(L, R);
    lazy = -1;
  }
};
void propagate(node *curr, int b, int e) {
  int mid = (b + e) >> 1;
  if (~curr->lazy) {
    curr->value = curr->lazy;
    if (b != e) {
      if (!curr->l) curr->l = new node(b, mid);
      if (!curr->r) curr->r = new node(mid + 1, e);
      (curr->l)->lazy = (curr->r)->lazy = curr->lazy;
    }
    curr->lazy = -1;
  }
}
void update(int b, int e, node *curr, int L, int R, int val) {
  propagate(curr, b, e);
  if (b > R || e < L) return;
  if (b >= L && e <= R) {
    curr->lazy = val;
    propagate(curr, b, e);
    return;
  }
  int mid = (b + e) >> 1;
  if (!curr->l) curr->l = new node(b, mid);
  if (!curr->r) curr->r = new node(mid + 1, e);
  if (mid >= R) {
    update(b, mid, curr->l, L, R, val);
    update(mid + 1, e, curr->r, L, R, val);
  } else if (L > mid) {
    update(b, mid, curr->l, L, R, val);
    update(mid + 1, e, curr->r, L, R, val);
  } else {
    update(b, mid, curr->l, L, mid, val);
    update(mid + 1, e, curr->r, mid + 1, R, val);
  }
  curr->value = min((curr->l)->value, (curr->r)->value);
}
int query(int b, int e, node *curr, int L, int R) {
  propagate(curr, b, e);
  if (b > R || e < L) return INT_MAX;
  if (b >= L && e <= R) {
    return curr->value;
  }
  int mid = (b + e) >> 1;
  if (!curr->l) curr->l = new node(b, mid);
  if (!curr->r) curr->r = new node(mid + 1, e);
  int res;
  if (mid >= R) {
    res = query(b, mid, curr->l, L, R);
    query(mid + 1, e, curr->r, L, R);
  } else if (L > mid) {
    res = query(mid + 1, e, curr->r, L, R);
    query(b, mid, curr->l, L, R);
  } else {
    res = min(query(b, mid, curr->l, L, mid),
              query(mid + 1, e, curr->r, mid + 1, R));
  }
  curr->value = min((curr->l)->value, (curr->r)->value);
  return res;
}
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> dp[i][0];
  }
  for (int i = 1; i < 19; i++)
    for (int j = 0; j < n; j++)
      dp[j][i] = min(dp[j][i - 1], dp[j + (1 << (i - 1))][i - 1]);
  int q;
  cin >> q;
  node *root = new node(0, n * k - 1);
  for (int i = 1; i <= q; i++) {
    int typ;
    cin >> typ;
    if (typ == 1) {
      int l, r, x;
      cin >> l >> r >> x;
      update(0, n * k - 1, root, l - 1, r - 1, x);
    } else {
      int l, r;
      cin >> l >> r;
      cout << query(0, n * k - 1, root, l - 1, r - 1) << endl;
    }
  }
}

### Prompt

Your task is to create 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 = 300001;
int dp[N][19], n;
int query(int l, int r) {
  int m = log2(r - l + 1);
  return min(dp[l][m], dp[r - (1 << m) + 1][m]);
}
int Q(int L, int R) {
  if (R - L + 1 >= n) return query(0, n - 1);
  L %= n;
  R %= n;
  if (L > R) {
    return min(query(L, n - 1), query(0, R));
  }
  return query(L, R);
}
struct node {
  int value, lazy;
  node *l, *r;
  node(int L, int R) {
    l = r = nullptr;
    value = Q(L, R);
    lazy = -1;
  }
};
void propagate(node *curr, int b, int e) {
  int mid = (b + e) >> 1;
  if (~curr->lazy) {
    curr->value = curr->lazy;
    if (b != e) {
      if (!curr->l) curr->l = new node(b, mid);
      if (!curr->r) curr->r = new node(mid + 1, e);
      (curr->l)->lazy = (curr->r)->lazy = curr->lazy;
    }
    curr->lazy = -1;
  }
}
void update(int b, int e, node *curr, int L, int R, int val) {
  propagate(curr, b, e);
  if (b > R || e < L) return;
  if (b >= L && e <= R) {
    curr->lazy = val;
    propagate(curr, b, e);
    return;
  }
  int mid = (b + e) >> 1;
  if (!curr->l) curr->l = new node(b, mid);
  if (!curr->r) curr->r = new node(mid + 1, e);
  if (mid >= R) {
    update(b, mid, curr->l, L, R, val);
    update(mid + 1, e, curr->r, L, R, val);
  } else if (L > mid) {
    update(b, mid, curr->l, L, R, val);
    update(mid + 1, e, curr->r, L, R, val);
  } else {
    update(b, mid, curr->l, L, mid, val);
    update(mid + 1, e, curr->r, mid + 1, R, val);
  }
  curr->value = min((curr->l)->value, (curr->r)->value);
}
int query(int b, int e, node *curr, int L, int R) {
  propagate(curr, b, e);
  if (b > R || e < L) return INT_MAX;
  if (b >= L && e <= R) {
    return curr->value;
  }
  int mid = (b + e) >> 1;
  if (!curr->l) curr->l = new node(b, mid);
  if (!curr->r) curr->r = new node(mid + 1, e);
  int res;
  if (mid >= R) {
    res = query(b, mid, curr->l, L, R);
    query(mid + 1, e, curr->r, L, R);
  } else if (L > mid) {
    res = query(mid + 1, e, curr->r, L, R);
    query(b, mid, curr->l, L, R);
  } else {
    res = min(query(b, mid, curr->l, L, mid),
              query(mid + 1, e, curr->r, mid + 1, R));
  }
  curr->value = min((curr->l)->value, (curr->r)->value);
  return res;
}
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> dp[i][0];
  }
  for (int i = 1; i < 19; i++)
    for (int j = 0; j < n; j++)
      dp[j][i] = min(dp[j][i - 1], dp[j + (1 << (i - 1))][i - 1]);
  int q;
  cin >> q;
  node *root = new node(0, n * k - 1);
  for (int i = 1; i <= q; i++) {
    int typ;
    cin >> typ;
    if (typ == 1) {
      int l, r, x;
      cin >> l >> r >> x;
      update(0, n * k - 1, root, l - 1, r - 1, x);
    } else {
      int l, r;
      cin >> l >> r;
      cout << query(0, n * k - 1, root, l - 1, r - 1) << endl;
    }
  }
}

```