#include <bits/stdc++.h>
using namespace std;
const int inf = 2e9;
const long long INF = 4e18;
const int ALPHA = 2;
const int LOG = 30;
struct vertex {
  int val;
  vertex *p[ALPHA];
  vertex() {
    val = 0;
    p[0] = p[1] = nullptr;
  }
};
vertex *root;
void add(int x) {
  vertex *v = root;
  v->val++;
  bool c;
  for (int i = LOG - 1; i >= 0; --i) {
    c = (1 << i) & x;
    if (v->p[c] == nullptr) {
      v->p[c] = new vertex;
    }
    v = v->p[c];
    v->val++;
  }
}
void rem(int x) {
  vertex *v = root;
  v->val--;
  bool c;
  for (int i = LOG - 1; i >= 0; --i) {
    c = (1 << i) & x;
    if (v->p[c] == nullptr) {
      v->p[c] = new vertex;
    }
    v = v->p[c];
    v->val--;
  }
}
int calc(int a, int b) {
  vertex *v = root;
  bool b1, b2;
  int ans = 0;
  for (int i = LOG - 1; i >= 0; --i) {
    b1 = (1 << i) & a;
    b2 = (1 << i) & b;
    if (b1 == 1 && v->p[b2] != nullptr) {
      ans += v->p[b2]->val;
    }
    if (v->p[b1 ^ b2] == nullptr) {
      break;
    }
    v = v->p[b1 ^ b2];
  }
  return ans;
}
void solve() {
  root = new vertex;
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int t;
    cin >> t;
    if (t == 1) {
      int x;
      cin >> x;
      add(x);
    }
    if (t == 2) {
      int x;
      cin >> x;
      rem(x);
    }
    if (t == 3) {
      int a, b;
      cin >> a >> b;
      cout << calc(b, a) << endl;
    }
  }
}
int main() {
  int t;
  ios::sync_with_stdio(0);
  cin.tie(0);
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
