#include <bits/stdc++.h>
using namespace std;
void write(int x) {
  if (x > 9) write(x / 10);
  putchar('0' + x % 10);
}
int input() {
  int res = 0;
  char c = ' ';
  while (c < '0') c = getchar();
  while (c >= '0') res = res * 10 + (c - '0'), c = getchar();
  return res;
}
const int N = 5e6;
int leaf = 1, ptr0[N], ptr1[N], sum[N];
void push(int v) {
  if (!ptr0[v]) ptr0[v] = ++leaf;
  if (!ptr1[v]) ptr1[v] = ++leaf;
}
void update(vector<char> x, int val) {
  int v = 1;
  for (auto i : x) {
    sum[v] += val, push(v);
    if (i)
      v = ptr1[v];
    else
      v = ptr0[v];
  }
  sum[v] += val;
}
int get(vector<char> x, vector<char> l) {
  int v = 1, res = 0;
  for (int I = 0; I < x.size(); ++I) {
    push(v);
    auto i = x[I], j = l[I];
    if (!i && !j) v = ptr0[v];
    if (!i && j) res += sum[ptr0[v]], v = ptr1[v];
    if (i && !j) v = ptr1[v];
    if (i && j) res += sum[ptr1[v]], v = ptr0[v];
  }
  return res;
}
vector<char> f(int x) {
  vector<char> res;
  while (x) res.push_back(x & 1), x >>= 1;
  while (res.size() < 31) res.push_back(0);
  reverse(res.begin(), res.end());
  return res;
}
int main() {
  for (int q = input(); q; --q) {
    int t = input();
    if (t != 3)
      update(f(input()), (t == 1 ? 1 : -1));
    else {
      int x = input(), l = input();
      write(get(f(x), f(l))), putchar('\n');
    }
  }
}
