#include <bits/stdc++.h>
using namespace std;
int read() {
  char c = getchar();
  int u = 0, f = 1;
  while (c != '-' && (c < '0' || '9' < c)) c = getchar();
  if (c == '-') {
    f = -1;
    c = getchar();
  }
  while ('0' <= c && c <= '9') {
    u = u * 10 + c - '0';
    c = getchar();
  }
  return u * f;
}
struct node {
  int l, r;
  int x, y;
};
node rr[5000222];
int cur = 1, n;
int s[100005];
int dp[100005][20];
void RMQ_init() {
  for (int i = 1; i <= n; i++) dp[i][0] = s[i];
  for (int j = 1; (1 << j) <= n; j++)
    for (int i = 1; i + (1 << j) - 1 <= n; i++)
      dp[i][j] = min(dp[i][j - 1], dp[i + (1 << (j - 1))][j - 1]);
}
int RMQ(int l, int r) {
  int k = int(log((double)(r - l + 1)) / log(2.0));
  return min(dp[l][k], dp[r - (1 << k) + 1][k]);
}
int query_rmq(int L, int R) {
  if (R - L + 1 >= n)
    return RMQ(1, n);
  else {
    int l = (L - 1) % n + 1;
    int r = (R - 1) % n + 1;
    if (r >= l)
      return RMQ(l, r);
    else
      return min(RMQ(l, n), RMQ(1, r));
  }
}
void push_down(int tt) {
  if (rr[tt].y == 1) {
    if (rr[tt].l == 0) rr[tt].l = ++cur;
    rr[rr[tt].l].x = rr[tt].x;
    rr[rr[tt].l].y = 1;
    if (rr[tt].r == 0) rr[tt].r = ++cur;
    rr[rr[tt].r].x = rr[tt].x;
    rr[rr[tt].r].y = 1;
  }
  rr[tt].y = 0;
}
int query(int L, int R, int l, int r, int tt) {
  if (tt == 0) {
    return query_rmq(l, r);
  }
  if (l == L && r == R) {
    return rr[tt].x;
  }
  push_down(tt);
  int mid = (L + R) / 2;
  if (mid >= r) {
    return query(L, mid, l, r, rr[tt].l);
  } else if (mid < l) {
    return query(mid + 1, R, l, r, rr[tt].r);
  } else {
    return min(query(L, mid, l, mid, rr[tt].l),
               query(mid + 1, R, mid + 1, r, rr[tt].r));
  }
}
void add(int L, int R, int l, int r, int x, int tt) {
  if (l == L && r == R) {
    rr[tt].x = x;
    rr[tt].y = 1;
    return;
  }
  push_down(tt);
  int mid = (L + R) / 2;
  if (mid >= r) {
    if (rr[tt].l == 0) rr[tt].l = ++cur;
    add(L, mid, l, r, x, rr[tt].l);
  } else if (mid < l) {
    if (rr[tt].r == 0) rr[tt].r = ++cur;
    add(mid + 1, R, l, r, x, rr[tt].r);
  } else {
    if (rr[tt].l == 0) rr[tt].l = ++cur;
    add(L, mid, l, mid, x, rr[tt].l);
    if (rr[tt].r == 0) rr[tt].r = ++cur;
    add(mid + 1, R, mid + 1, r, x, rr[tt].r);
  }
  rr[tt].x = min(rr[tt].l == 0 ? query_rmq(L, mid) : rr[rr[tt].l].x,
                 rr[tt].r == 0 ? query_rmq(mid + 1, R) : rr[rr[tt].r].x);
}
int main() {
  int m, k, l, r, x, t;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    s[i] = read();
  }
  RMQ_init();
  rr[1].x = RMQ(1, n);
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    t = read();
    if (t == 1) {
      l = read();
      r = read();
      x = read();
      add(1, n * k, l, r, x, 1);
    } else {
      l = read();
      r = read();
      printf("%d\n", query(1, n * k, l, r, 1));
    }
  }
  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;
int read() {
  char c = getchar();
  int u = 0, f = 1;
  while (c != '-' && (c < '0' || '9' < c)) c = getchar();
  if (c == '-') {
    f = -1;
    c = getchar();
  }
  while ('0' <= c && c <= '9') {
    u = u * 10 + c - '0';
    c = getchar();
  }
  return u * f;
}
struct node {
  int l, r;
  int x, y;
};
node rr[5000222];
int cur = 1, n;
int s[100005];
int dp[100005][20];
void RMQ_init() {
  for (int i = 1; i <= n; i++) dp[i][0] = s[i];
  for (int j = 1; (1 << j) <= n; j++)
    for (int i = 1; i + (1 << j) - 1 <= n; i++)
      dp[i][j] = min(dp[i][j - 1], dp[i + (1 << (j - 1))][j - 1]);
}
int RMQ(int l, int r) {
  int k = int(log((double)(r - l + 1)) / log(2.0));
  return min(dp[l][k], dp[r - (1 << k) + 1][k]);
}
int query_rmq(int L, int R) {
  if (R - L + 1 >= n)
    return RMQ(1, n);
  else {
    int l = (L - 1) % n + 1;
    int r = (R - 1) % n + 1;
    if (r >= l)
      return RMQ(l, r);
    else
      return min(RMQ(l, n), RMQ(1, r));
  }
}
void push_down(int tt) {
  if (rr[tt].y == 1) {
    if (rr[tt].l == 0) rr[tt].l = ++cur;
    rr[rr[tt].l].x = rr[tt].x;
    rr[rr[tt].l].y = 1;
    if (rr[tt].r == 0) rr[tt].r = ++cur;
    rr[rr[tt].r].x = rr[tt].x;
    rr[rr[tt].r].y = 1;
  }
  rr[tt].y = 0;
}
int query(int L, int R, int l, int r, int tt) {
  if (tt == 0) {
    return query_rmq(l, r);
  }
  if (l == L && r == R) {
    return rr[tt].x;
  }
  push_down(tt);
  int mid = (L + R) / 2;
  if (mid >= r) {
    return query(L, mid, l, r, rr[tt].l);
  } else if (mid < l) {
    return query(mid + 1, R, l, r, rr[tt].r);
  } else {
    return min(query(L, mid, l, mid, rr[tt].l),
               query(mid + 1, R, mid + 1, r, rr[tt].r));
  }
}
void add(int L, int R, int l, int r, int x, int tt) {
  if (l == L && r == R) {
    rr[tt].x = x;
    rr[tt].y = 1;
    return;
  }
  push_down(tt);
  int mid = (L + R) / 2;
  if (mid >= r) {
    if (rr[tt].l == 0) rr[tt].l = ++cur;
    add(L, mid, l, r, x, rr[tt].l);
  } else if (mid < l) {
    if (rr[tt].r == 0) rr[tt].r = ++cur;
    add(mid + 1, R, l, r, x, rr[tt].r);
  } else {
    if (rr[tt].l == 0) rr[tt].l = ++cur;
    add(L, mid, l, mid, x, rr[tt].l);
    if (rr[tt].r == 0) rr[tt].r = ++cur;
    add(mid + 1, R, mid + 1, r, x, rr[tt].r);
  }
  rr[tt].x = min(rr[tt].l == 0 ? query_rmq(L, mid) : rr[rr[tt].l].x,
                 rr[tt].r == 0 ? query_rmq(mid + 1, R) : rr[rr[tt].r].x);
}
int main() {
  int m, k, l, r, x, t;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    s[i] = read();
  }
  RMQ_init();
  rr[1].x = RMQ(1, n);
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    t = read();
    if (t == 1) {
      l = read();
      r = read();
      x = read();
      add(1, n * k, l, r, x, 1);
    } else {
      l = read();
      r = read();
      printf("%d\n", query(1, n * k, l, r, 1));
    }
  }
  return 0;
}

```