#include <bits/stdc++.h>
using namespace std;
const int MX = 100005, MY = MX * 2;
const int D = 1000, E = MX / D + 5;
map<int, int> mp;
int pm[MY];
int mi(int i) {
  if (mp.find(i) == mp.end()) {
    pm[(int)(mp).size()] = i;
    mp.insert(pair<int, int>(i, (int)(mp).size()));
  }
  return mp[i];
}
int a[MX];
int f[E][MY];
struct bit {
  vector<int> d;
  int sz;
  bit() {}
  bit(int mx) {
    sz = 1;
    while (sz < mx) sz <<= 1;
    d.resize(sz + 1);
    init(mx);
  }
  void init(int mx) {
    sz = 1;
    while (sz < mx) sz <<= 1;
  }
  void add(int i, int x = 1) {
    for (i = MX - 2 - i; i <= sz; i += i & -i) d[i] += x;
  }
  int sum(int i) {
    int x = 0;
    for (i = MX - 2 - i; i; i -= i & -i) x += d[i];
    return x;
  }
} d[E];
void up(int v, int p, int x) {
  for (int i = (p - 1) / D + 1; i < E; ++i) {
    d[i].add(f[i][v], -1);
    f[i][v] += x;
    d[i].add(f[i][v], 1);
  }
}
int sol1(int p) {
  int v = a[p];
  int ap = (p - 1) / D, bp = (p - 1) % D + 1, sp = D * ap;
  int res = f[ap][v];
  for (int i = 1; i <= bp; i++) res += (a[sp + i] == v);
  return res;
}
int cnt[MY];
int sol2(int p) {
  int ap = (p - 1) / D, bp = (p - 1) % D + 1, sp = D * ap;
  int pi = sol1(p);
  int res = d[ap].sum(pi);
  for (int i = 1; i <= bp; i++) {
    int x = a[sp + i];
    cnt[x]++;
    res += (cnt[x] + f[ap][x] == pi);
  }
  for (int i = 0; i < bp + 1; i++) cnt[a[sp + i]] = 0;
  return res;
}
int main() {
  for (int i = 0; i < E; i++) d[i] = bit(MX);
  int n, q;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    a[i] = mi(a[i]);
    up(a[i], i, 1);
  }
  scanf("%d", &q);
  for (int qi = 0; qi < q; qi++) {
    int ty, x, y;
    scanf("%d%d%d", &ty, &x, &y);
    if (ty == 1) {
      up(a[y], y, -1);
      a[y] = mi(x);
      up(a[y], y, 1);
    } else {
      int ans = 0;
      if (x == 1)
        ans = pm[a[y]];
      else if (x % 2 == 0)
        ans = sol1(y);
      else
        ans = sol2(y);
      printf("%d\n", ans);
    }
  }
  return 0;
}
