#include <bits/stdc++.h>
using namespace std;
const int Max = 1e5 + 10;
const int LOG = 30;
struct Trie {
  int l[Max * LOG], r[Max * LOG];
  int sz = 1;
  int val[Max * LOG];
  void insert(int x) {
    int pos = 1;
    for (int i = LOG; i--;) {
      val[pos]++;
      if ((1 << i) & x)
        if (r[pos])
          pos = r[pos];
        else
          pos = r[pos] = ++sz;
      else if (l[pos])
        pos = l[pos];
      else
        pos = l[pos] = ++sz;
    }
    val[pos]++;
  }
  void rmv(int x) {
    int pos = 1;
    for (int i = LOG; i--;) {
      val[pos]--;
      if ((1 << i) & x)
        pos = r[pos];
      else
        pos = l[pos];
    }
    val[pos]--;
  }
  int get(int x, int y) {
    int pos = 1;
    int ans = 0;
    for (int i = LOG; i--;) {
      if ((1 << i) & y) {
        if ((1 << i) & x) {
          ans += val[r[pos]];
          pos = l[pos];
        } else {
          ans += val[l[pos]];
          pos = r[pos];
        }
      } else if ((1 << i) & x)
        pos = r[pos];
      else
        pos = l[pos];
    }
    return ans;
  }
};
Trie trie;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  while (q--) {
    int ty;
    cin >> ty;
    if (ty == 1) {
      int x;
      cin >> x;
      trie.insert(x);
    } else if (ty == 2) {
      int x;
      cin >> x;
      trie.rmv(x);
    } else {
      int p, l;
      cin >> p >> l;
      cout << trie.get(p, l) << '\n';
    }
  }
}
