#include <bits/stdc++.h>
using namespace std;
template <typename _T>
inline void _DBG(const char *s, _T x) {
  cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a) {
  while (*s != ',') cerr << *s++;
  cerr << " = " << x << ',';
  _DBG(s + 1, a...);
}
template <typename TP>
struct dFenwick {
  long long N = 1e18 + 7;
  unordered_map<long long, TP> tree;
  dFenwick() {}
  dFenwick(long long n) : N(n + 1) {}
  void update(long long id, TP val) {
    for (long long i = id + 1; i <= N; i += (i & -i)) tree[i] += val;
  }
  TP pref(long long x) {
    TP res = 0;
    for (long long i = x; i; i -= (i & -i))
      if (tree.find(i) != tree.end()) res += tree[i];
    return res;
  }
  TP query(long long l, long long r) { return pref(r + 1) - pref(l); }
};
dFenwick<long long> tree(2e8 + 7);
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  while (q--) {
    int t, p;
    cin >> t >> p;
    if (t == 1)
      tree.update(p, 1);
    else if (t == 2)
      tree.update(p, -1);
    else {
      int l;
      cin >> l;
      int ll = 0, pp = 0;
      long long res = 0;
      for (int b = 31; b >= 0; b--) {
        if ((p >> b) & 1) pp += (1 << b);
        if ((l >> b) & 1) {
          int x = ll ^ pp;
          res += tree.query(x, x + (1 << b) - 1);
          ll += (1 << b);
        }
      }
      cout << res << "\n";
    }
  }
  return 0;
}
