#include <bits/stdc++.h>
using namespace std;
const int N = 6e6 + 10, M = 30;
int cnt[N], trie[N][2], tot = 1, n;
inline int read() {
  int x = 0, k = 1;
  char c = getchar();
  for (; c < 48 || c > 57; c = getchar()) k ^= (c == '-');
  for (; c >= 48 && c <= 57; c = getchar()) x = x * 10 + (c ^ 48);
  return k ? x : -x;
}
inline void add(int x, int dg) {
  int p = 1;
  for (int i = M; i >= 0; --i) {
    if (dg == 1)
      trie[p][((x >> i) & 1)] =
          (trie[p][((x >> i) & 1)] != 0) ? trie[p][((x >> i) & 1)] : (++tot);
    p = trie[p][((x >> i) & 1)], cnt[p] += dg;
  }
}
inline int ask(int x, int y) {
  int p = 1;
  int sum = 0;
  for (int i = M; i >= 0; i--) {
    int t = ((y >> i) & 1), t1 = ((x >> i) & 1);
    if (t)
      sum += cnt[trie[p][t1]], p = trie[p][t1 ^ 1];
    else
      p = trie[p][t1];
  }
  return sum;
}
int main() {
  n = read();
  while (n--) {
    int opt = read(), x = read();
    if (opt == 1)
      add(x, 1);
    else if (opt == 2)
      add(x, -1);
    else if (opt == 3) {
      int y = read();
      printf("%d\n", ask(x, y));
    }
  }
  return 0;
}
