#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n, a[maxn], tot = 1, val[32 * maxn], trie[maxn * 32][2], k;
void Insert(int num) {
  int root = 0;
  for (int i = 31; i >= 0; i--) {
    int id = (num >> i) & 1;
    if (!trie[root][id]) trie[root][id] = tot++;
    root = trie[root][id];
    val[root]++;
  }
}
void update(int num) {
  int root = 0;
  for (int i = 31; i >= 0; i--) {
    int id = (num >> i) & 1;
    root = trie[root][id];
    val[root]--;
  }
}
long long query(int num, int x) {
  int root = 0;
  long long ans = 0;
  for (int i = 31; i >= 0; i--) {
    int id = (num >> i) & 1, kk = (x >> i) & 1;
    if (kk == 1) {
      ans += val[trie[root][id]];
      root = trie[root][id ^ 1];
    } else {
      root = trie[root][id];
    }
    if (root == 0) break;
  }
  return ans;
}
int main() {
  scanf("%d", &n);
  while (n--) {
    int op, x, y;
    scanf("%d", &op);
    if (op == 1) {
      scanf("%d", &x);
      Insert(x);
    }
    if (op == 2) {
      scanf("%d", &x);
      update(x);
    }
    if (op == 3) {
      scanf("%d%d", &x, &y);
      long long ans = query(x, y);
      printf("%lld\n", ans);
    }
  }
  return 0;
}
