#include <bits/stdc++.h>
using namespace std;
template <class T>
void read(T& x) {
  x = 0;
  int w = 0;
  char g = getchar();
  while (!isdigit(g)) {
    w = (g == '-');
    g = getchar();
  }
  while (isdigit(g)) {
    x = (x << 3) + (x << 1) + (g xor 48);
    g = getchar();
  }
  x = w ? -x : x;
  return;
}
int q, op, pi, li, ans, cnt = 1, tot[3100005], trie[3100006][2];
inline void add(int u, int v) {
  bool num;
  int now = 1;
  for (register int i = 1 << 30; i; i >>= 1) {
    tot[now] += v;
    num = u & i;
    if (!trie[now][num]) trie[now][num] = ++cnt;
    now = trie[now][num];
  }
  tot[now] += v;
}
inline int ask(int u, int v) {
  bool vis1, vis2;
  int now = 1, ans = 0;
  for (register int i = 1 << 30; i; i >>= 1) {
    vis1 = u & i;
    vis2 = v & i;
    if (vis1 < vis2) ans += tot[trie[now][0]];
    if (vis1 && vis2) ans += tot[trie[now][1]];
    if (!vis2)
      now = trie[now][vis1];
    else
      now = trie[now][vis1 ^ 1];
  }
  return ans;
}
int main() {
  read(q);
  for (register int w = 1; w <= q; w++) {
    read(op);
    if (op == 1) {
      read(pi);
      add(pi, 1);
    }
    if (op == 2) {
      read(pi);
      add(pi, -1);
    }
    if (op == 3) {
      read(pi), read(li);
      cout << ask(pi, li) << "\n";
    }
  }
  return 0;
}
