#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
struct trie {
  int to[2], sz;
  trie() {
    to[0] = to[1] = -1;
    sz = 0;
  }
};
int ptr = 1;
const int N = 31;
vector<trie> v;
void update(int x, int val) {
  int cur = 0;
  v[cur].sz += val;
  for (int i = N; i >= 0; --i) {
    bool bit = x & (1 << i);
    int to = v[cur].to[bit];
    if (to == -1) {
      v.emplace_back();
      to = v[cur].to[bit] = ptr++;
    }
    cur = to;
    v[cur].sz += val;
  }
}
int query(int p, int l) {
  int cur = 0, ans = 0;
  for (int i = N; i >= 0; --i) {
    if (cur == -1 or v[cur].sz == 0) break;
    bool bitp = p & (1 << i), bitl = l & (1 << i);
    bool tek = bitp ^ bitl;
    if (bitl) {
      int to = v[cur].to[tek ^ 1];
      ans += to == -1 ? 0 : v[to].sz;
    }
    cur = v[cur].to[tek];
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int q;
  cin >> q;
  v.emplace_back();
  while (q--) {
    int opt, p;
    cin >> opt >> p;
    if (opt == 1) {
      update(p, +1);
    } else if (opt == 2) {
      update(p, -1);
    } else {
      int l;
      cin >> l;
      cout << query(p, l) << "\n";
    }
  }
  return 0;
}
