#include <bits/stdc++.h>
using namespace std;
const int N = 100004;
struct hm {
  int ch[3], num;
};
hm trie[50 * N];
int q, pi, li, type, dem = 1;
int get(int x, int i) { return (x >> i) & 1; }
void Push(int key, int val) {
  int u = 1;
  trie[u].num++;
  for (int i = 30; i >= 0; i--) {
    int t = get(key, i);
    if (trie[u].ch[t] == 0) trie[u].ch[t] = ++dem;
    u = trie[u].ch[t];
    trie[u].num += val;
  }
}
int solve() {
  int res = 0;
  int u = 1;
  for (int i = 30; i >= 0; i--) {
    int t1 = get(pi, i), t2 = get(li, i);
    if (t1 == 0 && t2 == 0) u = trie[u].ch[0];
    if (t1 == 0 && t2 == 1) res += trie[trie[u].ch[0]].num, u = trie[u].ch[1];
    if (t1 == 1 && t2 == 1) res += trie[trie[u].ch[1]].num, u = trie[u].ch[0];
    if (t1 == 1 && t2 == 0) u = trie[u].ch[1];
  }
  return res;
}
int main() {
  cin >> q;
  while (q--) {
    cin >> type;
    if (type == 1) {
      cin >> pi;
      Push(pi, 1);
    }
    if (type == 2) {
      cin >> pi;
      Push(pi, -1);
    }
    if (type == 3) {
      cin >> pi >> li;
      cout << solve() << endl;
    }
  }
}
