#include <bits/stdc++.h>
using namespace std;
const int MAXA = 4e6 + 10;
const int LOG = 30;
const int ALPHA = 2;
int T, n, trie[MAXA][ALPHA], cnt[MAXA], vercnt = 1;
void add(int x) {
  int v = 0;
  cnt[0]++;
  for (int i = LOG; i >= 0; i--) {
    int tmp = ((x >> i) & 1);
    if (trie[v][tmp] == -1) trie[v][tmp] = vercnt++;
    v = trie[v][tmp];
    cnt[v]++;
  }
}
void remove(int x) {
  int v = 0;
  cnt[0]--;
  for (int i = LOG; i >= 0; i--) {
    int tmp = ((x >> i) & 1);
    if (cnt[trie[v][tmp]] == 1) {
      trie[v][tmp] = -1;
      break;
    }
    v = trie[v][tmp];
    cnt[v]--;
  }
}
int Calc(int p, int l) {
  int v = 0;
  int ans = 0;
  for (int i = LOG; i >= 0; i--) {
    int tmp1 = ((p >> i) & 1);
    int tmp2 = ((l >> i) & 1);
    if (tmp2 == 0) {
      if (trie[v][tmp1] == -1) break;
      v = trie[v][tmp1];
    } else {
      ans += (trie[v][tmp1] == -1 ? 0 : cnt[trie[v][tmp1]]);
      if (trie[v][!tmp1] == -1) break;
      v = trie[v][(!tmp1)];
    }
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  T = 1;
  while (T--) {
    memset(trie, -1, sizeof trie);
    cin >> n;
    for (int i = 1; i <= n; i++) {
      int a, b;
      cin >> a >> b;
      if (a == 1)
        add(b);
      else if (a == 2)
        remove(b);
      else {
        int c;
        cin >> c;
        cout << Calc(b, c) << '\n';
      }
    }
  }
  return 0;
}
