#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int LN = N * 20 * 8;
int n, k;
int b[N];
int size;
int l[LN], r[LN], v[LN];
bool lz[LN];
inline int newnode(int left, int right, int value = -1) {
  size = (size + 1) % LN;
  l[size] = left;
  r[size] = right;
  if (value == -1) {
    lz[size] = false;
    v[size] = min(v[left], v[right]);
  } else {
    lz[size] = true;
    v[size] = value;
  }
  return size;
}
inline void push_bees(int p, int L, int R) {
  if (lz[p]) {
    lz[p] = false;
    if (L != R) {
      l[p] = newnode(0, 0, v[p]);
      r[p] = newnode(0, 0, v[p]);
    }
  }
}
int build_bees(int L = 0, int R = n - 1) {
  if (L == R) return newnode(0, 0, b[L]);
  return newnode(build_bees(L, ((L + R) >> 1)),
                 build_bees(((L + R) >> 1) + 1, R));
}
int update_bees(int p, int a, int b, int x, int L = 0, int R = n - 1) {
  push_bees(p, L, R);
  if (b < L || R < a) return p;
  if (a <= L && R <= b) return newnode(0, 0, x);
  return newnode(update_bees(l[p], a, b, x, L, ((L + R) >> 1)),
                 update_bees(r[p], a, b, x, ((L + R) >> 1) + 1, R));
}
int query_bees(int p, int a, int b, int L = 0, int R = n - 1) {
  push_bees(p, L, R);
  if (b < L || R < a) return INT_MAX;
  if (a <= L && R <= b) return v[p];
  return min(query_bees(l[p], a, b, L, ((L + R) >> 1)),
             query_bees(r[p], a, b, ((L + R) >> 1) + 1, R));
}
int tree[N];
const int NN = 10005;
int st[NN << 2];
bool laz[NN << 2];
inline void pull(int p) { st[p] = min(st[(p << 1)], st[(p << 1) | 1]); }
void build(int v, int p = 1, int L = 0, int R = k - 1) {
  laz[p] = false;
  if (L == R) {
    st[p] = v;
    return;
  }
  build(v, (p << 1), L, ((L + R) >> 1));
  build(v, (p << 1) | 1, ((L + R) >> 1) + 1, R);
  pull(p);
}
inline void push(int p, int L, int R) {
  if (laz[p]) {
    laz[p] = false;
    if (L != R) {
      st[(p << 1)] = st[(p << 1) | 1] = st[p];
      laz[(p << 1)] = laz[(p << 1) | 1] = true;
    } else {
      tree[L] = update_bees(tree[L], 0, n - 1, st[p]);
    }
  }
}
void update(int a, int b, int v, int p = 1, int L = 0, int R = k - 1) {
  push(p, L, R);
  if (b < L || R < a) return;
  if (a <= L && R <= b) {
    st[p] = v;
    laz[p] = true;
    push(p, L, R);
    return;
  }
  update(a, b, v, (p << 1), L, ((L + R) >> 1));
  update(a, b, v, (p << 1) | 1, ((L + R) >> 1) + 1, R);
  pull(p);
}
int query(int a, int b, int p = 1, int L = 0, int R = k - 1) {
  push(p, L, R);
  if (b < L || R < a) return INT_MAX;
  if (a <= L && R <= b) return st[p];
  int q = min(query(a, b, (p << 1), L, ((L + R) >> 1)),
              query(a, b, (p << 1) | 1, ((L + R) >> 1) + 1, R));
  pull(p);
  return q;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; ++i) scanf("%d", &b[i]);
  int root = build_bees();
  fill(tree, tree + k, root);
  build(v[root]);
  int q;
  scanf("%d", &q);
  while (q--) {
    int cmd, a, b;
    scanf("%d%d%d", &cmd, &a, &b);
    --a, --b;
    int ai = a / n, aj = a % n;
    int bi = b / n, bj = b % n;
    if (cmd == 2) {
      if (ai == bi) {
        query(ai, ai);
        printf("%d\n", query_bees(tree[ai], aj, bj));
      } else if (ai < bi) {
        query(ai, ai);
        query(bi, bi);
        int mn =
            min(query_bees(tree[ai], aj, n - 1), query_bees(tree[bi], 0, bj));
        if (ai + 1 <= bi - 1) mn = min(mn, query(ai + 1, bi - 1));
        printf("%d\n", mn);
      }
    } else {
      int x;
      scanf("%d", &x);
      if (ai == bi) {
        query(ai, ai);
        int p = update_bees(tree[ai], aj, bj, x);
        update(ai, ai, v[p]);
        tree[ai] = p;
      } else if (ai < bi) {
        query(ai, ai);
        query(bi, bi);
        int p = update_bees(tree[ai], aj, n - 1, x);
        int q = update_bees(tree[bi], 0, bj, x);
        update(ai, ai, v[p]);
        update(bi, bi, v[q]);
        tree[ai] = p;
        tree[bi] = q;
        if (ai + 1 <= bi - 1) update(ai + 1, bi - 1, x);
      }
    }
  }
}

### 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 = 100005;
const int LN = N * 20 * 8;
int n, k;
int b[N];
int size;
int l[LN], r[LN], v[LN];
bool lz[LN];
inline int newnode(int left, int right, int value = -1) {
  size = (size + 1) % LN;
  l[size] = left;
  r[size] = right;
  if (value == -1) {
    lz[size] = false;
    v[size] = min(v[left], v[right]);
  } else {
    lz[size] = true;
    v[size] = value;
  }
  return size;
}
inline void push_bees(int p, int L, int R) {
  if (lz[p]) {
    lz[p] = false;
    if (L != R) {
      l[p] = newnode(0, 0, v[p]);
      r[p] = newnode(0, 0, v[p]);
    }
  }
}
int build_bees(int L = 0, int R = n - 1) {
  if (L == R) return newnode(0, 0, b[L]);
  return newnode(build_bees(L, ((L + R) >> 1)),
                 build_bees(((L + R) >> 1) + 1, R));
}
int update_bees(int p, int a, int b, int x, int L = 0, int R = n - 1) {
  push_bees(p, L, R);
  if (b < L || R < a) return p;
  if (a <= L && R <= b) return newnode(0, 0, x);
  return newnode(update_bees(l[p], a, b, x, L, ((L + R) >> 1)),
                 update_bees(r[p], a, b, x, ((L + R) >> 1) + 1, R));
}
int query_bees(int p, int a, int b, int L = 0, int R = n - 1) {
  push_bees(p, L, R);
  if (b < L || R < a) return INT_MAX;
  if (a <= L && R <= b) return v[p];
  return min(query_bees(l[p], a, b, L, ((L + R) >> 1)),
             query_bees(r[p], a, b, ((L + R) >> 1) + 1, R));
}
int tree[N];
const int NN = 10005;
int st[NN << 2];
bool laz[NN << 2];
inline void pull(int p) { st[p] = min(st[(p << 1)], st[(p << 1) | 1]); }
void build(int v, int p = 1, int L = 0, int R = k - 1) {
  laz[p] = false;
  if (L == R) {
    st[p] = v;
    return;
  }
  build(v, (p << 1), L, ((L + R) >> 1));
  build(v, (p << 1) | 1, ((L + R) >> 1) + 1, R);
  pull(p);
}
inline void push(int p, int L, int R) {
  if (laz[p]) {
    laz[p] = false;
    if (L != R) {
      st[(p << 1)] = st[(p << 1) | 1] = st[p];
      laz[(p << 1)] = laz[(p << 1) | 1] = true;
    } else {
      tree[L] = update_bees(tree[L], 0, n - 1, st[p]);
    }
  }
}
void update(int a, int b, int v, int p = 1, int L = 0, int R = k - 1) {
  push(p, L, R);
  if (b < L || R < a) return;
  if (a <= L && R <= b) {
    st[p] = v;
    laz[p] = true;
    push(p, L, R);
    return;
  }
  update(a, b, v, (p << 1), L, ((L + R) >> 1));
  update(a, b, v, (p << 1) | 1, ((L + R) >> 1) + 1, R);
  pull(p);
}
int query(int a, int b, int p = 1, int L = 0, int R = k - 1) {
  push(p, L, R);
  if (b < L || R < a) return INT_MAX;
  if (a <= L && R <= b) return st[p];
  int q = min(query(a, b, (p << 1), L, ((L + R) >> 1)),
              query(a, b, (p << 1) | 1, ((L + R) >> 1) + 1, R));
  pull(p);
  return q;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; ++i) scanf("%d", &b[i]);
  int root = build_bees();
  fill(tree, tree + k, root);
  build(v[root]);
  int q;
  scanf("%d", &q);
  while (q--) {
    int cmd, a, b;
    scanf("%d%d%d", &cmd, &a, &b);
    --a, --b;
    int ai = a / n, aj = a % n;
    int bi = b / n, bj = b % n;
    if (cmd == 2) {
      if (ai == bi) {
        query(ai, ai);
        printf("%d\n", query_bees(tree[ai], aj, bj));
      } else if (ai < bi) {
        query(ai, ai);
        query(bi, bi);
        int mn =
            min(query_bees(tree[ai], aj, n - 1), query_bees(tree[bi], 0, bj));
        if (ai + 1 <= bi - 1) mn = min(mn, query(ai + 1, bi - 1));
        printf("%d\n", mn);
      }
    } else {
      int x;
      scanf("%d", &x);
      if (ai == bi) {
        query(ai, ai);
        int p = update_bees(tree[ai], aj, bj, x);
        update(ai, ai, v[p]);
        tree[ai] = p;
      } else if (ai < bi) {
        query(ai, ai);
        query(bi, bi);
        int p = update_bees(tree[ai], aj, n - 1, x);
        int q = update_bees(tree[bi], 0, bj, x);
        update(ai, ai, v[p]);
        update(bi, bi, v[q]);
        tree[ai] = p;
        tree[bi] = q;
        if (ai + 1 <= bi - 1) update(ai + 1, bi - 1, x);
      }
    }
  }
}

```