#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
const long long maxn = (long long)2e5 + 100;
const long long maxm = (long long)52;
const int LOGN = 30;
const long long INF = 1e13;
const long long MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-12;
struct Node {
  int cnt;
  int nxt[2];
  Node() : cnt(0) { nxt[0] = 0, nxt[1] = 0; }
};
vector<Node> a;
void Init() {
  a.resize(0);
  a.push_back(Node());
}
void Insert(int x) {
  int p = 0;
  for (int i = LOGN; i >= 0; --i) {
    int nxt = (((x) & (1 << (i))) != 0);
    if (a[p].nxt[nxt] == 0) {
      a.push_back(Node());
      a[p].nxt[nxt] = a.size() - 1;
    }
    p = a[p].nxt[nxt];
    a[p].cnt++;
  }
}
void Del(int x) {
  int p = 0;
  for (int i = LOGN; i >= 0; --i) {
    int nxt = (((x) & (1 << (i))) != 0);
    int pos = a[p].nxt[nxt];
    if (pos == 0) {
      a.push_back(Node());
    }
    p = pos;
    a[p].cnt--;
  }
}
int Query(int x, int l) {
  int p = 0;
  int ans = 0;
  for (int i = LOGN; i >= 0; --i) {
    int lnxt = (((l) & (1 << (i))) != 0);
    int xnxt = (((x) & (1 << (i))) != 0);
    if (lnxt == 1) {
      if (xnxt == 0) {
        ans += a[a[p].nxt[0]].cnt;
        p = a[p].nxt[1];
      } else {
        ans += a[a[p].nxt[1]].cnt;
        p = a[p].nxt[0];
      }
    } else {
      p = a[p].nxt[xnxt];
    }
    if (p == 0) break;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  while (cin >> n) {
    Init();
    for (int i = (0); i < ((n)); ++i) {
      int op;
      cin >> op;
      if (op == 1) {
        int x;
        cin >> x;
        Insert(x);
      } else if (op == 2) {
        int x;
        cin >> x;
        Del(x);
      } else {
        int x, l;
        cin >> x >> l;
        int ans = Query(x, l);
        cout << ans << endl;
      }
    }
  }
  return 0;
}
