#include <bits/stdc++.h>
using namespace std;
struct trie {
  int cnt;
  int son[2];
} tree[5000010];
int n, num = 1;
void add(int x, int y) {
  int u = 1;
  for (int i = 30; i >= 0; i--) {
    int now = (x >> i) & 1;
    if (!tree[u].son[now]) tree[u].son[now] = ++num;
    u = tree[u].son[now];
    tree[u].cnt += y;
  }
}
int query(int x, int y) {
  int u = 1, ans = 0;
  for (int i = 30; i >= 0; i--) {
    if ((y >> i) & 1) {
      ans += tree[tree[u].son[(x >> i) & 1]].cnt;
      u = tree[u].son[((x >> i) & 1) ^ 1];
    } else {
      u = tree[u].son[(x >> i) & 1];
    }
    if (u == 0) break;
  }
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int opt, a, b;
    scanf("%d", &opt);
    if (opt == 1) {
      scanf("%d", &a);
      add(a, 1);
    }
    if (opt == 2) {
      scanf("%d", &a);
      add(a, -1);
    }
    if (opt == 3) {
      scanf("%d%d", &a, &b);
      printf("%d\n", query(a, b));
    }
  }
}
