#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
struct node {
  int next[2];
  int cnt;
};
node make_node() {
  node nd;
  nd.cnt = 0;
  nd.next[0] = nd.next[1] = -1;
  return nd;
}
node t[MAXN * 30];
int sz = 0;
int bs = 29;
void add(int tiv, int d) {
  (0);
  int v = 0;
  for (int i = bs; i >= 0; i--) {
    int bit = (tiv >> i) & 1;
    t[v].cnt += d;
    ;
    (0);
    if (t[v].next[bit] == -1) {
      t[sz] = make_node();
      t[v].next[bit] = sz++;
    }
    v = t[v].next[bit];
  }
  t[v].cnt += d;
  (0);
  (0);
}
int query(int p, int l) {
  int res = 0;
  int v = 0;
  int val = 0;
  for (int i = bs; i >= 0; i--) {
    (0);
    int pi = (p >> i) & 1;
    int li = (l >> i) & 1;
    if (li == 1) {
      int nxt = t[v].next[pi];
      if (nxt != -1)
        res += t[nxt].cnt;
      else
        (0);
      if (t[v].next[1 - pi] == -1)
        return res;
      else {
        v = t[v].next[1 - pi];
      }
    } else {
      if (t[v].next[pi] == -1) return res;
      v = t[v].next[pi];
    }
  }
  return res;
}
int main() {
  t[0] = make_node();
  sz = 1;
  int q;
  scanf("%d", &q);
  int op, p, l;
  for (int qq = 0; qq < q; qq++) {
    scanf("%d%d", &op, &p);
    if (op == 1) {
      add(p, 1);
    } else if (op == 2) {
      add(p, -1);
    } else {
      scanf("%d", &l);
      int res = query(p, l);
      cout << res << endl;
      ;
    }
  }
  return 0;
}
