#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const long long M = (long long)1e9 + 7;
int Int() {
  int x;
  scanf("%d", &x);
  return x;
}
long long Long() {
  long long x;
  scanf("%lld", &x);
  return x;
}
void Char(char *ch) { scanf("%s", ch); }
template <typename t>
inline t abs(t a) {
  if (a >= 0) return a;
  return -a;
}
template <typename T>
inline T modpow(T b, T p, T Mod) {
  T res = 1;
  while (p) {
    if (p & 1) {
      res *= b;
      res %= Mod;
    }
    b *= b;
    b %= Mod;
    p >>= 1;
  }
  return res;
}
template <typename T>
inline T ModInv(T b, T Mod) {
  return modpow(b, Mod - 2, Mod);
}
template <typename T>
inline T pwr(T b, T p) {
  T res = 1;
  while (p) {
    if (p & 1) {
      res *= b;
    }
    b *= b;
    p >>= 1;
  }
  return res;
}
template <typename T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <typename T>
inline void Int(T &n) {
  n = 0;
  int f = 1;
  register int ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
  n = n * f;
}
template <typename T, typename U>
inline void Int(T &a, U &b) {
  Int(a);
  Int(b);
}
template <typename T, typename U, typename W>
inline void Int(T &a, U &b, W &c) {
  Int(a, b);
  Int(c);
}
template <typename T, typename U, typename W, typename X>
inline void Int(T &a, U &b, W &c, X &d) {
  Int(a, b, c);
  Int(d);
}
vector<int> Unique(vector<int> v) {
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  return v;
}
vector<string> split(const string &s, char c) {
  vector<string> v;
  stringstream ss(s);
  string x;
  while (getline(ss, x, c)) v.emplace_back(x);
  return move(v);
}
void err(vector<string>::iterator it) {}
template <typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
  cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << " ";
  err(++it, args...);
}
struct node {
  int cnt;
  node *tree[2];
  node() {
    cnt = 0;
    tree[0] = tree[1] = NULL;
  }
} * root;
void add(int x) {
  node *cur = root;
  for (int i = 30; i >= 0; i--) {
    int f = (bool)(x & (1 << i));
    if (cur->tree[f] == NULL) {
      cur->tree[f] = new node();
    }
    cur = cur->tree[f];
    cur->cnt++;
  }
}
int sum(int x, int k) {
  int res = 0;
  node *cur = root;
  for (int i = 30; i >= 0; i--) {
    int p = (bool)(x & (1 << i));
    int q = (bool)(k & (1 << i));
    if (q == 0) {
      if (p == 1) {
        if (cur->tree[1] != NULL) {
          cur = cur->tree[1];
        } else {
          return res;
        }
      } else {
        if (cur->tree[0] != NULL) {
          cur = cur->tree[0];
        } else {
          return res;
        }
      }
    } else {
      if (p == 1) {
        if (cur->tree[1] != NULL) res += cur->tree[1]->cnt;
        if (cur->tree[0] != NULL) {
          cur = cur->tree[0];
        } else {
          return res;
        }
      } else {
        if (cur->tree[0] != NULL) res += cur->tree[0]->cnt;
        if (cur->tree[1] != NULL) {
          cur = cur->tree[1];
        } else {
          return res;
        }
      }
    }
  }
  return res;
}
void del(int x) {
  node *cur = root;
  for (int i = 30; i >= 0; i--) {
    int f = (bool)(x & (1 << i));
    cur = cur->tree[f];
    cur->cnt--;
  }
}
int main() {
  int t = 1, tc = 0;
  while (t--) {
    root = new node();
    int q = Int();
    while (q--) {
      int d = Int();
      if (d == 1) {
        int x = Int();
        add(x);
      } else if (d == 2) {
        int x = Int();
        del(x);
      } else {
        int x = Int(), k = Int();
        printf("%d\n", sum(x, k));
      }
    }
  }
  return 0;
}
