#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool NextInteger(T &res) {
  char c;
  bool negative = false;
  while (c = getchar(), c != '-' && !('0' <= c && c <= '9'))
    if (c == EOF) return false;
  if (c == '-') negative = true, c = getchar();
  res = 0;
  while ('0' <= c && c <= '9') res *= 10, res += c - '0', c = getchar();
  if (negative) res *= -1;
  return true;
}
template <typename T>
void PrintInteger(T x) {
  if (x < 0) putchar('-'), x *= -1;
  if (x > 9) PrintInteger(x / 10);
  putchar(x % 10 + '0');
}
map<unsigned int, unsigned int> tree;
unsigned int INDEX(unsigned int x, unsigned int n) {
  unsigned int cur = 0;
  for (unsigned int y = 1 << 31, i = 0; i < n; y >>= 1, i++)
    cur = cur * 2 + ((x & y) == 0 ? 1 : 2);
  return cur;
}
void MODIFY(unsigned int x, unsigned int d) {
  unsigned int cur = 0;
  tree[cur] += d;
  for (unsigned int y = 1 << 31, i = 0; i < 30; y >>= 1, i++)
    cur = cur * 2 + ((x & y) == 0 ? 1 : 2), tree[cur] += d;
}
int main() {
  long q;
  NextInteger(q);
  while (q--) {
    unsigned int type, p, l;
    NextInteger(type);
    if (type != 3)
      NextInteger(p), MODIFY(p << 2, type == 1 ? 1 : -1);
    else {
      NextInteger(p), NextInteger(l);
      p <<= 2, l <<= 2;
      unsigned int x = p ^ l, ans = 0;
      for (unsigned int i = 0, y = 1 << 31; i < 30; y >>= 1, i++)
        if ((l & y) != 0) ans += tree[INDEX(x ^ y, i + 1)];
      PrintInteger(ans);
      putchar('\n');
    }
  }
  return 0;
}
