#include <bits/stdc++.h>
using namespace std;
struct Node {
  long long nxt[2];
  long long cnt = 0;
  Node() { nxt[0] = nxt[1] = -1; };
};
long long n, q, x, l, t;
vector<Node> trie;
void insert(int idx, int now, int val) {
  if (now == 0) {
    trie[idx].cnt++;
    return;
  }
  bool on = (val & (1LL << (now - 1)));
  if (trie[idx].nxt[on] == -1) {
    trie[idx].nxt[on] = trie.size();
    trie.push_back(Node());
  }
  insert(trie[idx].nxt[on], now - 1, val);
  trie[idx].cnt++;
}
void erase(long long idx, long long now, long long val) {
  if (now == 0) {
    trie[idx].cnt--;
    return;
  }
  bool on = (val & (1LL << (now - 1)));
  erase(trie[idx].nxt[on], now - 1, val);
  trie[idx].cnt--;
}
long long getVal(int idx, int now, int val, int limit) {
  if (now == 0) {
    return 0;
  }
  bool on = (val & (1LL << (now - 1)));
  long long ret = 0;
  if ((limit & (1LL << (now - 1))) && trie[idx].nxt[(on ^ 1)] != -1) {
    ret += trie[trie[idx].nxt[(on ^ 1)]].cnt;
  }
  if (trie[idx].nxt[on] == -1) {
    return ret;
  }
  ret += getVal(trie[idx].nxt[on], now - 1, val, limit);
  return ret;
}
void reset() {}
void input() { cin >> q; }
void solve() {
  trie.push_back(Node());
  while (q--) {
    cin >> t >> x;
    if (t == 1) {
      insert(0, 28, x);
    } else if (t == 2) {
      erase(0, 28, x);
    } else {
      cin >> l;
      cout << getVal(0, 28, (x ^ l), l) << endl;
    }
  }
}
void LetsRock() { solve(); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  input();
  reset();
  LetsRock();
  return 0;
}
