#include <bits/stdc++.h>
using namespace std;
struct Tries {
  int sz;
  Tries *child[2];
  Tries() {
    sz = 0;
    for (int i = 0; i <= 1; i++) child[i] = NULL;
  }
};
Tries T;
bool bit(int x, int i) { return (x >> i) & 1; }
void upd(Tries *p, int x, int h, int val) {
  p->sz += val;
  if (h < 0) return;
  for (int i = 0; i <= 1; i++) {
    if (bit(x, h) == i && p->child[i] == NULL) p->child[i] = new Tries;
    if (p->child[i] == NULL || bit(x, h) != i) continue;
    upd(p->child[i], x, h - 1, val);
  }
}
int get_sz(Tries *p) {
  if (p == NULL) return 0;
  return p->sz;
}
int get_ans(Tries *p, int x, int l, int h) {
  if (p == NULL || h < 0) return 0;
  int y = (bool)(x & 1 << h);
  if (l & 1 << h)
    return get_sz(p->child[y]) + get_ans(p->child[!y], x, l, h - 1);
  return get_ans(p->child[y], x, l, h - 1);
}
int main() {
  int q;
  cin >> q;
  Tries *p = &T;
  while (q--) {
    int type, x, l;
    cin >> type >> x;
    if (type == 1)
      upd(p, x, 30, 1);
    else if (type == 2)
      upd(p, x, 30, -1);
    else {
      cin >> l;
      cout << get_ans(p, x, l, 30) << endl;
    }
  }
}
