#include <bits/stdc++.h>
using namespace std;
const int Max = 1e9 + 100;
const long long int MAX = 1e18 + 500;
const int sz = 2e6 + 100;
struct node {
  int ara[2];
  bool leaf;
  int cnt[2];
};
node ara[sz];
string Binary(int val) {
  string str = "";
  while (val) {
    if ((val & 1) != 0)
      str = "1" + str;
    else
      str = "0" + str;
    val >>= 1;
  }
  str = string(30 - str.length(), '0') + str;
  return str;
}
int root;
int last = 0;
void add(int val) {
  string str = Binary(val);
  int len = str.length();
  int cur = root;
  for (int i = 0; i < len; i++) {
    int id = str[i] - '0';
    if (ara[cur].ara[id] == -1) ara[cur].ara[id] = ++last;
    ++ara[cur].cnt[id];
    cur = ara[cur].ara[id];
  }
  ara[cur].leaf = true;
}
int ans = 0;
void query(int p, int l) {
  string P = Binary(p);
  string L = Binary(l);
  int cur = 0;
  int len = P.length();
  for (int i = 0; i < len; i++) {
    if (L[i] == '1') {
      if (P[i] == '1') {
        ans += ara[cur].cnt[1];
        if (ara[cur].ara[0] != -1)
          cur = ara[cur].ara[0];
        else
          return;
      } else {
        ans += ara[cur].cnt[0];
        if (ara[cur].ara[1] != -1)
          cur = ara[cur].ara[1];
        else
          return;
      }
    } else {
      if (P[i] == '0' && ara[cur].ara[0] != -1) {
        cur = ara[cur].ara[0];
      } else if (P[i] == '1' && ara[cur].ara[1] != -1) {
        cur = ara[cur].ara[1];
      } else
        return;
    }
  }
}
void Del(string str, int cur, int p) {
  if (p >= str.length()) return;
  int id = str[p] - '0';
  if (ara[cur].ara[id] != -1) Del(str, ara[cur].ara[id], p + 1);
  if (ara[cur].cnt[id] == 1) ara[cur].ara[id] = -1;
  --ara[cur].cnt[id];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int a, b, c, i, j, k, q, p, x, y, ct, ct1, m, l, r, x1, y1, mn, h, sum1, in,
      z, mid, n, mx;
  char ch;
  double d;
  string str1, str2, str;
  bool bl, bl1;
  int t, cs = 1;
  for (int i = 0; i < sz; i++) {
    for (int j = 0; j < 2; j++) ara[i].cnt[j] = 0, ara[i].ara[j] = -1;
  }
  cin >> q;
  while (q--) {
    int mark;
    cin >> mark;
    if (mark == 1) {
      cin >> x;
      add(x);
    } else if (mark == 2) {
      cin >> x;
      string le = Binary(x);
      Del(le, 0, 0);
    } else {
      cin >> x >> y;
      ans = 0;
      query(x, y);
      cout << ans << '\n';
    }
  }
}
