#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const int maxN = 209;
struct Node {
  bool endOfWord;
  Node* next[2];
  int cnt = 0;
  Node() {
    endOfWord = false;
    for (int i = (0); i <= ((2) - 1); ++i) next[i] = NULL;
  }
};
void insert(string s, Node* root) {
  Node* curr = root;
  for (int i = (0); i <= (((int)s.size()) - 1); ++i) {
    Node* next = curr->next[s[i] - '0'];
    if (next == NULL) {
      next = new Node();
      curr->next[s[i] - '0'] = next;
    }
    curr->cnt++;
    curr = next;
  }
  curr->cnt++;
}
bool deleteN(string s, Node* root, int size) {
  if (root == NULL) return false;
  Node* curr = root;
  if (size == (int)s.size()) {
    curr->cnt--;
    if (curr->cnt > 0) return false;
    return true;
  }
  curr->cnt--;
  bool x = deleteN(s, curr->next[s[size] - '0'], size + 1);
  if (x) {
    curr->next[s[size] - '0'] = NULL;
    if (curr->cnt > 0) return false;
    for (int i = (0); i <= ((2) - 1); ++i)
      if (curr->next[i] != NULL) return false;
    return true;
  }
  return false;
}
string p, l;
int query(Node* root, int cnt) {
  if (root == NULL || cnt >= p.size()) return 0;
  if (p[cnt] == '0' && l[cnt] == '0') {
    return query(root->next[0], cnt + 1);
  }
  if (p[cnt] == '1' && l[cnt] == '0') {
    return query(root->next[1], cnt + 1);
  }
  if (p[cnt] == '0' && l[cnt] == '1') {
    int ans = 0;
    ans += root->cnt;
    if (root->next[1] != NULL) {
      ans -= root->next[1]->cnt;
    }
    return query(root->next[1], cnt + 1) + ans;
  }
  if (p[cnt] == '1' && l[cnt] == '1') {
    int ans = 0;
    ans += root->cnt;
    if (root->next[0] != NULL) ans -= root->next[0]->cnt;
    return query(root->next[0], cnt + 1) + ans;
  }
  return inf;
}
void printTrie(Node* root, string acu) {
  if (root->endOfWord) cout << acu << endl;
  for (int i = (0); i <= ((2) - 1); ++i)
    if (root->next[i] != NULL) {
      printTrie(root->next[i], acu + char(i + '0'));
    }
}
int main() {
  int q, a, num;
  ios_base::sync_with_stdio(0);
  cin >> q;
  Node* root = new Node();
  while (q--) {
    cin >> a >> num;
    bitset<28> bs = num;
    if (a == 1) insert(bs.to_string(), root);
    if (a == 2) deleteN(bs.to_string(), root, 0);
    if (a == 3) {
      int x;
      cin >> x;
      p = bs.to_string();
      bitset<28> bs2 = x;
      l = bs2.to_string();
      cout << query(root, 0) << endl;
    }
  }
  return 0;
}
