#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2, typename T3>
class triple {
 public:
  T1 first;
  T2 second;
  T3 third;
  triple() {
    first = 0;
    second = 0;
    third = 0;
  }
};
const int maxn = 4e6 + 10;
const int LOG = 30;
long long num;
long long a[maxn];
long long g[maxn][3];
void Add(const long long &p, const long long &u) {
  long long v = 1;
  a[v] = a[v] + u;
  for (int((i)) = ((LOG - 1)); ((i)) >= (0); ((i))--) {
    bool x = (p & (1 << i));
    if (!g[v][x]) g[v][x] = ++num;
    v = g[v][x];
    a[v] = a[v] + u;
  }
}
long long Ans(const long long &p, const long long &l) {
  long long res = 0;
  long long v = 1;
  for (int((i)) = ((LOG - 1)); ((i)) >= (0); ((i))--) {
    bool flag1 = (p & (1 << i));
    bool flag2 = flag1 ^ 1;
    int x = g[v][flag1];
    int y = g[v][flag2];
    if (l & (1 << i)) {
      if (x) res = res + a[x];
      if (!y or !a[y]) return res;
      v = y;
    } else {
      if (!x or !a[x]) return res;
      v = x;
    }
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  long long q;
  num = 1;
  cin >> q;
  while (q--) {
    int t, p, l;
    cin >> t >> p;
    if (t == 1) Add(p, 1);
    if (t == 2) Add(p, -1);
    if (t == 3) {
      cin >> l;
      cout << Ans(p, l) << '\n';
    }
  }
  return 0;
}
