#include <bits/stdc++.h>
using namespace std;
const int N = 100000;
struct node {
  node() {}
  node(int val, int size = 1, node* left = 0, node* right = 0)
      : val(val), lazy(val), _left(left), _right(right), size(size) {}
  node(node* l, node* r)
      : _left(l),
        _right(r),
        lazy(0),
        val(min(l->val, r->val)),
        size(l->size + r->size) {}
  node* _left;
  node* _right;
  int val;
  int lazy;
  int size;
};
int n, k, q, res;
int a[N];
vector<node> roots;
deque<node> buf;
template <class... types>
node* createNode(types... args) {
  buf.emplace_back(args...);
  return &buf.back();
}
node* build(int v, int sz) {
  if (sz == 1) {
    return createNode(a[v]);
  } else {
    int mid = sz / 2;
    if (sz & 1) ++mid;
    return createNode(build(v, mid), build(v + mid, sz - mid));
  }
}
node* build(node* root, int sz) {
  if (sz == 1) {
    return root;
  } else {
    int mid = sz / 2;
    if (sz & 1) ++mid;
    return createNode(build(root, mid), build(root, sz - mid));
  }
}
node* push(node* ptr) {
  if (ptr->lazy) {
    node *ll = 0, *lr = 0, *rl = 0, *rr = 0;
    int sl = 1, sr = 1;
    if (ptr->_left) {
      sl = ptr->_left->size;
      ll = ptr->_left->_left;
      lr = ptr->_left->_right;
    }
    if (ptr->_right) {
      sr = ptr->_right->size;
      rl = ptr->_right->_left;
      rr = ptr->_right->_right;
    }
    return createNode((ptr->_left ? createNode(ptr->lazy, sl, ll, lr) : 0),
                      (ptr->_right ? createNode(ptr->lazy, sr, rl, rr) : 0));
  }
  return ptr;
}
node* update(node* ptr, int l, int r, int val) {
  int sz = ptr->size;
  if (r - l + 1 == sz && !l) {
    return createNode(val, ptr->size, ptr->_left, ptr->_right);
  } else {
    ptr = push(ptr);
    int mid = ptr->_left->size;
    node *lt = ptr->_left, *rt = ptr->_right;
    if (mid > r) {
      lt = update(ptr->_left, l, r, val);
    } else if (l >= mid) {
      rt = update(ptr->_right, l - mid, r - mid, val);
    } else {
      lt = update(ptr->_left, l, mid - 1, val);
      rt = update(ptr->_right, 0, r - mid, val);
    }
    return createNode(lt, rt);
  }
}
node* get(node* ptr, int l, int r) {
  int sz = ptr->size;
  if (r - l + 1 == sz && !l) {
    res = min(res, ptr->val);
    return ptr;
  } else {
    ptr = push(ptr);
    int mid = ptr->_left->size;
    node *lt = ptr->_left, *rt = ptr->_right;
    if (mid > r) {
      lt = get(ptr->_left, l, r);
    } else if (l >= mid) {
      rt = get(ptr->_right, l - mid, r - mid);
    } else {
      lt = get(ptr->_left, l, mid - 1);
      rt = get(ptr->_right, 0, r - mid);
    }
    if (lt == ptr->_left && rt == ptr->_right) return ptr;
    return createNode(lt, rt);
  }
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  node* root = build(build(0, n), k);
  scanf("%d", &q);
  for (int i = 0; i < q; ++i) {
    int t, l, r;
    scanf("%d%d%d", &t, &l, &r);
    --l;
    --r;
    if (t == 1) {
      int x;
      scanf("%d", &x);
      root = update(root, l, r, x);
    } else {
      res = INT32_MAX;
      root = get(root, l, r);
      printf("%d\n", res);
    }
  }
  return 0;
}

### Prompt

In CPP, your task is to solve 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 = 100000;
struct node {
  node() {}
  node(int val, int size = 1, node* left = 0, node* right = 0)
      : val(val), lazy(val), _left(left), _right(right), size(size) {}
  node(node* l, node* r)
      : _left(l),
        _right(r),
        lazy(0),
        val(min(l->val, r->val)),
        size(l->size + r->size) {}
  node* _left;
  node* _right;
  int val;
  int lazy;
  int size;
};
int n, k, q, res;
int a[N];
vector<node> roots;
deque<node> buf;
template <class... types>
node* createNode(types... args) {
  buf.emplace_back(args...);
  return &buf.back();
}
node* build(int v, int sz) {
  if (sz == 1) {
    return createNode(a[v]);
  } else {
    int mid = sz / 2;
    if (sz & 1) ++mid;
    return createNode(build(v, mid), build(v + mid, sz - mid));
  }
}
node* build(node* root, int sz) {
  if (sz == 1) {
    return root;
  } else {
    int mid = sz / 2;
    if (sz & 1) ++mid;
    return createNode(build(root, mid), build(root, sz - mid));
  }
}
node* push(node* ptr) {
  if (ptr->lazy) {
    node *ll = 0, *lr = 0, *rl = 0, *rr = 0;
    int sl = 1, sr = 1;
    if (ptr->_left) {
      sl = ptr->_left->size;
      ll = ptr->_left->_left;
      lr = ptr->_left->_right;
    }
    if (ptr->_right) {
      sr = ptr->_right->size;
      rl = ptr->_right->_left;
      rr = ptr->_right->_right;
    }
    return createNode((ptr->_left ? createNode(ptr->lazy, sl, ll, lr) : 0),
                      (ptr->_right ? createNode(ptr->lazy, sr, rl, rr) : 0));
  }
  return ptr;
}
node* update(node* ptr, int l, int r, int val) {
  int sz = ptr->size;
  if (r - l + 1 == sz && !l) {
    return createNode(val, ptr->size, ptr->_left, ptr->_right);
  } else {
    ptr = push(ptr);
    int mid = ptr->_left->size;
    node *lt = ptr->_left, *rt = ptr->_right;
    if (mid > r) {
      lt = update(ptr->_left, l, r, val);
    } else if (l >= mid) {
      rt = update(ptr->_right, l - mid, r - mid, val);
    } else {
      lt = update(ptr->_left, l, mid - 1, val);
      rt = update(ptr->_right, 0, r - mid, val);
    }
    return createNode(lt, rt);
  }
}
node* get(node* ptr, int l, int r) {
  int sz = ptr->size;
  if (r - l + 1 == sz && !l) {
    res = min(res, ptr->val);
    return ptr;
  } else {
    ptr = push(ptr);
    int mid = ptr->_left->size;
    node *lt = ptr->_left, *rt = ptr->_right;
    if (mid > r) {
      lt = get(ptr->_left, l, r);
    } else if (l >= mid) {
      rt = get(ptr->_right, l - mid, r - mid);
    } else {
      lt = get(ptr->_left, l, mid - 1);
      rt = get(ptr->_right, 0, r - mid);
    }
    if (lt == ptr->_left && rt == ptr->_right) return ptr;
    return createNode(lt, rt);
  }
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  node* root = build(build(0, n), k);
  scanf("%d", &q);
  for (int i = 0; i < q; ++i) {
    int t, l, r;
    scanf("%d%d%d", &t, &l, &r);
    --l;
    --r;
    if (t == 1) {
      int x;
      scanf("%d", &x);
      root = update(root, l, r, x);
    } else {
      res = INT32_MAX;
      root = get(root, l, r);
      printf("%d\n", res);
    }
  }
  return 0;
}

```