#include <bits/stdc++.h>
using namespace std;
long long const sze = 1 << 17, MOD1 = 1e9 + 9, x1 = 119, INF = -1e6, psze = 30;
long long root = 1, my_free = 2;
struct node {
  long long A[2], cnt;
  node() { A[0] = A[1] = cnt = 0; }
};
node tree[sze * psze];
void add_number(long long v) {
  long long current = root;
  tree[current].cnt++;
  for (long long i = psze; i >= 0; i--) {
    long long label = ((1LL << i) & v) == 0 ? 0 : 1;
    if (!tree[current].A[label]) tree[current].A[label] = my_free++;
    current = tree[current].A[label];
    tree[current].cnt++;
  }
}
void delete_number(long long v) {
  long long current = root, prev;
  tree[current].cnt--;
  for (long long i = psze; i >= 0; i--) {
    long long label = ((1LL << i) & v) == 0 ? 0 : 1;
    prev = current;
    current = tree[current].A[label];
    tree[current].cnt--;
    if (!tree[current].cnt) tree[prev].A[label] = 0;
  }
}
long long get(long long v, long long l) {
  long long current = root;
  long long cnt = 0, ans = 0;
  for (long long i = psze; i >= 0; i--) {
    long long label = ((1LL << i) & v) == 0 ? 0 : 1;
    if (tree[current].A[0] && tree[current].A[1]) {
      if (cnt + (1LL << i) >= l) {
        ans += tree[tree[current].A[label ^ 1]].cnt;
        current = tree[current].A[label];
      } else {
        current = tree[current].A[label ^ 1];
        cnt += (1LL << i);
      }
    } else {
      if (tree[current].A[label ^ 1]) {
        if (cnt + (1LL << i) >= l)
          return ans + tree[tree[current].A[label ^ 1]].cnt;
        current = tree[current].A[label ^ 1];
        cnt += (1LL << i);
      } else {
        current = tree[current].A[label];
      }
    }
  }
  return ans;
}
signed main() {
  long long q;
  cin >> q;
  long long m = 0;
  for (long long i = 0; i < q; ++i) {
    long long label;
    cin >> label;
    if (label == 1) {
      long long v;
      cin >> v;
      add_number(v);
      m++;
    } else if (label == 2) {
      long long v;
      cin >> v;
      delete_number(v);
      m--;
    } else {
      long long a, b;
      cin >> a >> b;
      cout << m - get(a, b) << '\n';
    }
  }
  return 0;
}
