#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
  if (a < b) a = b;
}
inline void gn(int &first) {
  char c, sg = 0;
  while (c = getchar(), (c > '9' || c < '0') && c != '-')
    ;
  for ((c == '-' ? sg = 1, c = getchar() : 0), first = 0; c >= '0' && c <= '9';
       c = getchar())
    first = (first << 1) + (first << 3) + c - '0';
  if (sg) first = -first;
}
inline void print(int first) {
  if (first < 0) {
    putchar('-');
    return print(-first);
  }
  if (first < 10) {
    putchar('0' + first);
    return;
  }
  print(first / 10);
  putchar(first % 10 + '0');
}
int power(int a, int b, int m, int ans = 1) {
  for (; b; b >>= 1, a = 1LL * a * a % m)
    if (b & 1) ans = 1LL * ans * a % m;
  return ans;
}
struct Bit_Trie {
  int next[3000030][2], cnt[3000030];
  int size, root;
  void init() {
    root = size = 0;
    ++size;
  }
  void extend(int val) {
    int r = root, c;
    for (int i = 27; i >= 0; i--) {
      c = (val >> i) & 1;
      if (!next[r][c]) next[r][c] = size++;
      r = next[r][c];
      cnt[r]++;
    }
  }
  void del(int val) {
    int r = root, c;
    for (int i = 27; i >= 0; i--) {
      c = (val >> i) & 1;
      r = next[r][c];
      cnt[r]--;
    }
  }
  int calc(int a, int b) {
    int r = root, c, res = 0;
    for (int i = 27; i >= 0; i--) {
      c = ((a ^ b) >> i) & 1;
      if (next[r][!c] and ((b >> i) & 1)) res += cnt[next[r][!c]];
      if (next[r][c])
        r = next[r][c];
      else
        break;
    }
    return res;
  }
} soldier;
int main() {
  soldier.init();
  int q, tp, first, second;
  scanf("%d", &q);
  while (q--) {
    scanf("%d%d", &tp, &first);
    if (tp == 1)
      soldier.extend(first);
    else if (tp == 2)
      soldier.del(first);
    else {
      scanf("%d", &second);
      cout << soldier.calc(first, second) << endl;
    }
  }
  return 0;
}
