#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T& a) {
  T x = 0, s = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') s = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + (c ^ '0');
    c = getchar();
  }
  a = x * s;
  return;
}
struct tree {
  int ch[2];
  int sum;
  tree() {
    for (int i = 0; i < 2; i++) ch[i] = 0;
    return;
  }
} t[1000010 * 5];
int cnt = 1;
void build(int now, int x) {
  for (int i = (1 << 30); i; i >>= 1) {
    bool c = i & x;
    t[now].sum++;
    if (!t[now].ch[c]) t[now].ch[c] = ++cnt;
    now = t[now].ch[c];
  }
  t[now].sum++;
  return;
}
void del(int now, int x) {
  for (int i = (1 << 30); i; i >>= 1) {
    bool c = i & x;
    t[now].sum--;
    if (!t[now].ch[c]) t[now].ch[c] = ++cnt;
    now = t[now].ch[c];
  }
  t[now].sum--;
  return;
}
int query(int now, int x, int k) {
  bool c1, c2;
  int ans = 0;
  for (int i = 1 << 30; i; i >>= 1) {
    c1 = x & i, c2 = k & i;
    if (c1 < c2) ans += t[t[now].ch[0]].sum;
    if (c1 && c2) ans += t[t[now].ch[1]].sum;
    if (!c2)
      now = t[now].ch[c1];
    else
      now = t[now].ch[c1 ^ 1];
  }
  return ans;
}
int main() {
  int q;
  read(q);
  while (q--) {
    int opt, x, k;
    read(opt), read(x);
    if (opt == 1) {
      build(1, x);
    } else if (opt == 2) {
      del(1, x);
    } else {
      read(k);
      printf("%d\n", query(1, x, k));
    }
  }
  return 0;
}
