#include <bits/stdc++.h>
using namespace std;
inline long long rd() {
  long long x = 0;
  int ch = getchar(), f = 1;
  while (!isdigit(ch) && (ch != '-') && (ch != EOF)) ch = getchar();
  if (ch == '-') {
    f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void rt(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10)
    rt(x / 10), putchar(x % 10 + '0');
  else
    putchar(x + '0');
}
const int maxn = 100005, G = 26;
struct node {
  int size;
  node *to[2];
} a[maxn * 30], *null, *root;
int ndc;
node *newnode() {
  node *p = ++ndc + a;
  p->to[0] = p->to[1] = null;
  return p;
}
void add(int x, int v) {
  node *p = root;
  for (int i = int(G); i >= (int)(0); i--) {
    int dig = (x >> i) & 1;
    if (p->to[dig] == null) p->to[dig] = newnode();
    p = p->to[dig];
    p->size += v;
  }
}
int getans(int x, int l) {
  node *p = root;
  int ret = 0, nw = 0;
  for (int i = int(G); i >= (int)(0); i--) {
    if (p == null) return ret;
    int dig = (x >> i) & 1;
    if (nw + (1 << i) < l)
      ret += p->to[dig]->size, nw += 1 << i, p = p->to[dig ^ 1];
    else
      p = p->to[dig];
  }
  if (nw < l) ret += p->size;
  return ret;
}
int main() {
  null = a;
  null->to[0] = null->to[1] = null;
  root = newnode();
  for (int q = rd(); q--;) {
    int t = rd(), x = rd();
    if (t == 1) add(x, 1);
    if (t == 2) add(x, -1);
    if (t == 3) rt(getans(x, rd())), putchar('\n');
  }
}
