#include <bits/stdc++.h>
const int LEN = 30;
using namespace std;
inline bool bit(int mask, int idx) { return ((mask & (1 << idx)) != 0); }
struct trie {
  int leaves;
  trie *ref[2];
};
trie *root = nullptr;
void initialize(trie *init) {
  init->leaves = 0;
  for (int i = 0; i < 2; i++) init->ref[i] = nullptr;
}
void insert(int x) {
  trie *curr = root;
  for (int i = LEN; i >= 0; i--) {
    int dest = bit(x, i);
    if (curr->ref[dest] == nullptr) {
      curr->ref[dest] = new trie;
      initialize(curr->ref[dest]);
    }
    curr = curr->ref[dest];
    curr->leaves++;
  }
}
void erase(int x) {
  trie *curr = root;
  for (int i = LEN; i >= 0; i--) {
    int dest = bit(x, i);
    if (curr->ref[dest] == nullptr) {
      cout << "WTF?" << '\n';
      exit(0);
    }
    curr = curr->ref[dest];
    curr->leaves--;
  }
}
int cnt(int p, int l) {
  trie *curr = root;
  int res = 0;
  for (int i = LEN; i >= 0; i--) {
    if (curr == nullptr) return res;
    int a = bit(l, i), b = bit(p, i);
    if (a == 0) {
      if (b == 0)
        curr = curr->ref[0];
      else
        curr = curr->ref[1];
    } else {
      if (b == 0) {
        if (curr->ref[0] != nullptr) res += curr->ref[0]->leaves;
        curr = curr->ref[1];
      } else {
        if (curr->ref[1] != nullptr) res += curr->ref[1]->leaves;
        curr = curr->ref[0];
      }
    }
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  root = new trie;
  initialize(root);
  int q;
  cin >> q;
  while (q--) {
    int op, p;
    cin >> op >> p;
    if (op == 1)
      insert(p);
    else if (op == 2)
      erase(p);
    else {
      int l;
      cin >> l;
      cout << cnt(p, l) << '\n';
    }
  }
  return 0;
}
