#include <bits/stdc++.h>
using namespace std;
template <class X, class Y>
ostream& operator<<(ostream& os, const pair<X, Y>& p) {
  return os << "[" << p.first << ", " << p.second << "]";
}
template <class Ch, class Tr, class Container>
basic_ostream<Ch, Tr>& operator<<(basic_ostream<Ch, Tr>& os,
                                  const Container& x) {
  os << "{";
  bool f = 1;
  for (auto& y : x) {
    if (!f)
      os << ", ";
    else
      f = 0;
    os << y;
  }
  return os << "}";
}
struct Debug {
  template <class T>
  Debug& operator<<(const T& x) {
    return *this;
  }
};
struct Trie {
  vector<vector<int> > v;
  vector<int> cnt;
  Trie() {
    v.push_back(vector<int>(2, -1));
    cnt.push_back(0);
  }
  void insert(string& s, int d) {
    int cur = 0;
    for (int i = 0; i < s.size(); i++) {
      if (v[cur][s[i] - '0'] == -1) {
        v[cur][s[i] - '0'] = v.size();
        v.push_back(vector<int>(2, -1));
        cnt.push_back(0);
      }
      cur = v[cur][s[i] - '0'];
      cnt[cur] += d;
    }
  }
  int get(int node) {
    if (node == -1) return 0;
    return cnt[node];
  }
  int query(string& p, string& l) {
    int cur = 0, ret = 0;
    for (int i = 0; i < p.size() && cur != -1; i++) {
      if (l[i] == '1') {
        if (p[i] == '1') {
          ret += get(v[cur][1]);
          cur = v[cur][0];
        } else {
          ret += get(v[cur][0]);
          cur = v[cur][1];
        }
      } else {
        if (p[i] == '1') {
          cur = v[cur][1];
        } else {
          cur = v[cur][0];
        }
      }
    }
    return ret;
  }
};
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int q;
  cin >> q;
  Trie trie;
  while (q--) {
    int t;
    cin >> t;
    if (t == 1 || t == 2) {
      int p;
      cin >> p;
      string s = bitset<29>(p).to_string();
      trie.insert(s, t == 1 ? 1 : -1);
    } else {
      int p, l;
      cin >> p >> l;
      string s = bitset<29>(p).to_string();
      string ss = bitset<29>(l).to_string();
      cout << trie.query(s, ss) << '\n';
    }
  }
}
