#include <bits/stdc++.h>
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx,avx2")
inline int read() {
  int x = 0;
  char c = getchar();
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) x = (x << 3) + (x << 1) + c - 48, c = getchar();
  return x;
}
const int N = 1e5 + 7;
int n, _, sz, a[N];
int main() {
  n = read();
  for (int i = 1; i <= n; ++i) a[i] = read();
  _ = read();
  int ans = 0;
  while (_-- > 0) {
    int op = read(), l = read(), r = read();
    l = ((l + ans - 1) % n) + 1;
    r = ((r + ans - 1) % n) + 1;
    if (l > r) std::swap(l, r);
    if (op == 1) {
      int t = a[r];
      while (r > l) a[r] = a[r - 1], --r;
      a[l] = t;
    } else {
      int k = read();
      k = ((k + ans - 1) % n) + 1;
      int ret = 0;
      for (int i = l; i <= r; ++i) ret += a[i] == k;
      printf("%d\n", ans = ret);
    }
  }
  return 0;
}
