#include <bits/stdc++.h>
const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const long long MXLL = 9223372036854775807;
const int Sz = 1110111;
using namespace std;
inline void Read_rap() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
struct trie {
  int e[2];
  int cnt;
  trie() {
    memset(e, 0, sizeof e);
    cnt = 0;
  }
} t[Sz];
int N = 1;
const int L = 27;
int q;
inline void add(int x) {
  int v = 1;
  for (int i = L - 1; i >= 0; i--) {
    int bit = (x & (1 << i)) > 0;
    if (!t[v].e[bit]) t[v].e[bit] = ++N;
    v = t[v].e[bit];
    t[v].cnt++;
  }
}
inline void del(int x) {
  int v = 1;
  for (int i = L - 1; i >= 0; i--) {
    int bit = (x & (1 << i)) > 0;
    v = t[v].e[bit];
    t[v].cnt--;
  }
}
inline int get(int p, int l) {
  int res = 0;
  int v = 1;
  for (int i = L - 1; v && i >= 0; i--) {
    int b1 = (p & (1 << i)) > 0, b2 = (l & (1 << i)) > 0;
    if (b2) {
      res += t[t[v].e[b1]].cnt;
      v = t[v].e[b1 ^ 1];
    } else {
      v = t[v].e[b1];
    }
  }
  return res;
}
int main() {
  Read_rap();
  cin >> q;
  while (q--) {
    int tp, p;
    cin >> tp >> p;
    if (tp == 1) add(p);
    if (tp == 2) del(p);
    if (tp == 3) {
      int l;
      cin >> l;
      cout << get(p, l) << endl;
    }
  }
  return 0;
}
