#include <bits/stdc++.h>
using namespace std;
const int M = 100007;
const int N = 30 * M;
const int B = 26;
inline int rd() {
  int x = 0;
  bool f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (x == '-') f = 0;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - 48;
  return f ? x : -x;
}
int m;
int ch[N][2], tot;
int sz[N];
void ins(int d) {
  int x = 0, i, c;
  for (i = B; i >= 0; i--) {
    c = (d >> i) & 1;
    if (ch[x][c])
      x = ch[x][c];
    else
      x = ch[x][c] = ++tot;
    sz[x]++;
  }
}
void del(int d) {
  int x = 0, i, c;
  for (i = B; i >= 0; i--) {
    c = (d >> i) & 1;
    x = ch[x][c];
    sz[x]--;
  }
}
int get(int d, int D) {
  int x = 0, i, c, s, k, res = 0;
  for (i = B; i >= 0; i--) {
    c = (d >> i) & 1;
    s = (D >> i) & 1;
    for (k = 0; k < 2; k++)
      if ((c ^ k) < s) res += sz[ch[x][k]];
    if (ch[x][c ^ s])
      x = ch[x][c ^ s];
    else
      break;
  }
  return res;
}
int main() {
  int i, kd, x, y;
  m = rd();
  while (m--) {
    kd = rd();
    if (kd == 1)
      ins(rd());
    else if (kd == 2)
      del(rd());
    else {
      x = rd(), y = rd();
      printf("%d\n", get(x, y));
    }
  }
  return 0;
}
