#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long mod1 = 998244353;
const int N = 2e5 + 12;
struct trie {
  trie *bit[2];
  int cnt = 0;
};
trie *head;
void insert(int x) {
  trie *cur = head;
  for (int i = 30; i >= 0; i--) {
    int b = (x >> i) & 1;
    if (cur->bit[b] == NULL) {
      cur->bit[b] = new trie();
    }
    cur = cur->bit[b];
    cur->cnt++;
  }
}
void remove(int x) {
  trie *cur = head;
  for (int i = 30; i >= 0; i--) {
    int b = (x >> i) & 1;
    cur = cur->bit[b];
    cur->cnt--;
  }
}
int query(int b, int c) {
  trie *cur = head;
  int ans = 0;
  for (int i = 30; i >= 0; i--) {
    int x = (b >> i) & 1, y = (c >> i) & 1;
    if (y == 0) {
      if (cur->bit[x] == NULL) return ans;
      cur = cur->bit[x];
    } else if (y == 1 && x == 0) {
      if (cur->bit[0]) ans += cur->bit[0]->cnt;
      if (cur->bit[1])
        cur = cur->bit[1];
      else
        return ans;
    } else {
      if (cur->bit[1]) ans += cur->bit[1]->cnt;
      if (cur->bit[0] && (cur->bit[0]->cnt) > 0)
        cur = cur->bit[0];
      else
        return ans;
    }
  }
  return ans;
}
void solve() {
  int q;
  cin >> q;
  int a, b, c;
  head = new trie();
  while (q--) {
    cin >> a;
    if (a == 1) {
      cin >> b;
      insert(b);
    } else if (a == 2) {
      cin >> b;
      remove(b);
    } else {
      cin >> b >> c;
      cout << query(b, c) << "\n";
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
