#include <bits/stdc++.h>
using namespace std;
int n, p, l, type;
struct trie {
  trie* son[2];
  int sum;
  trie() {
    son[0] = son[1] = NULL;
    sum = 0;
  }
} * root;
template <class T>
void read(T& x, int f = 1) {
  char ch = getchar();
  x = 0;
  while (ch < '0' || ch > '9') f = (ch == '-' ? -1 : 1), ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - 48, ch = getchar();
  x *= f;
}
void insert(int p, int type) {
  trie* cur = root;
  for (int i = 31; ~i; i--) {
    int now = (p >> i) & 1;
    if (cur->son[now] == NULL) cur->son[now] = new trie;
    cur = cur->son[now];
    cur->sum += type;
  }
}
void query(int p, int l) {
  int ans = 0;
  trie* cur = root;
  for (int i = 31; ~i; i--) {
    bool pi = (p >> i) & 1;
    bool li = (l >> i) & 1;
    if (cur == NULL) break;
    if (li && cur->son[pi] != NULL) ans += cur->son[pi]->sum;
    cur = cur->son[pi ^ li];
  }
  printf("%d\n", ans);
}
int main() {
  read(n);
  root = new trie;
  for (int i = 1; i <= n; i++) {
    read(type), read(p);
    if (type == 1)
      insert(p, 1);
    else if (type == 2)
      insert(p, -1);
    else
      read(l), query(p, l);
  }
  return 0;
}
