#include <bits/stdc++.h>
using namespace std;
long long n, x, t, need;
struct TrieNode {
  long long Cnt, Bit;
  TrieNode *Next[2];
  TrieNode(long long b) {
    Cnt = 0;
    Bit = b;
    Next[0] = Next[1] = NULL;
  }
};
TrieNode *TrieRoot = new TrieNode(-1);
void TrieUpdate(long long j, TrieNode *Curr, long long add) {
  bool b = ((1LL << j) & x);
  if (Curr->Next[b] == NULL) Curr->Next[b] = new TrieNode(b);
  Curr->Next[b]->Cnt += add;
  if (j) TrieUpdate(j - 1, Curr->Next[b], add);
}
long long TrieXor(long long j, TrieNode *Curr) {
  bool b = (x & (1LL << j));
  if (need & (1LL << j))
    return ((Curr->Next[b] != NULL ? Curr->Next[b]->Cnt : 0)) +
           (Curr->Next[!b] != NULL ? TrieXor(j - 1, Curr->Next[!b]) : 0);
  else
    return (Curr->Next[b] != NULL ? TrieXor(j - 1, Curr->Next[b]) : 0);
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  while (n--) {
    cin >> t >> x;
    if (t == 1)
      TrieUpdate(31, TrieRoot, 1);
    else if (t == 2)
      TrieUpdate(31, TrieRoot, -1);
    else {
      cin >> need;
      cout << TrieXor(31, TrieRoot) << endl;
    }
  }
  return 0;
}
