#include <bits/stdc++.h>
using namespace std;
long long siz[2000010], ch[2000010][2], cnt = 1, q;
void ins(long long x, long long w) {
  long long now = 1;
  for (long long i = 30; i >= 0; i--) {
    siz[now] += w;
    long long qwq = (x >> i) & 1;
    if (!ch[now][qwq]) {
      ch[now][qwq] = ++cnt;
    }
    now = ch[now][qwq];
  }
  siz[now] += w;
}
long long query(long long x, long long y) {
  long long now = 1, ans = 0;
  for (long long i = 30; i >= 0; i--) {
    long long qwq = 0;
    for (long long j = 0; j <= 1; j++) {
      if ((j ^ ((x >> i) & 1)) < ((y >> i) & 1)) {
        ans += siz[ch[now][j]];
      } else if ((j ^ ((x >> i) & 1)) == ((y >> i) & 1)) {
        qwq = ch[now][j];
      }
    }
    if (!qwq) {
      break;
    }
    now = qwq;
  }
  return ans;
}
signed main() {
  cin >> q;
  for (long long i = 1; i <= q; i++) {
    long long opt, x, y;
    scanf("%lld%lld", &opt, &x);
    if (opt == 1) {
      ins(x, 1);
    }
    if (opt == 2) {
      ins(x, -1);
    }
    if (opt == 3) {
      scanf("%lld", &y);
      cout << query(x, y) << "\n";
    }
  }
}
