#include <bits/stdc++.h>
using namespace std;
const double g = 10.0, eps = 1e-9;
const int N = 100000 + 10, maxn = 3000 + 10, inf = 0x3f3f3f3f,
          INF = 0x3f3f3f3f3f3f3f3f;
struct Trie {
  int tot, root;
  int Next[N * 32][3], cnt[N * 32];
  int newnode() {
    memset(Next[tot], -1, sizeof Next[tot]);
    cnt[tot] = 0;
    return tot++;
  }
  void init() {
    tot = 0;
    root = newnode();
  }
  void ins(int x) {
    int now = root;
    for (int i = 30; i >= 0; i--) {
      if (Next[now][(x >> i) & 1] == -1) Next[now][(x >> i) & 1] = newnode();
      now = Next[now][(x >> i) & 1];
      cnt[now]++;
    }
  }
  void del(int x) {
    int now = root;
    for (int i = 30; i >= 0; i--) {
      cnt[Next[now][(x >> i) & 1]]--;
      if (cnt[Next[now][(x >> i) & 1]] == 0) {
        Next[now][(x >> i) & 1] = -1;
        break;
      }
      now = Next[now][(x >> i) & 1];
    }
  }
  int query(int x, int y) {
    int now = root, ans = 0;
    for (int i = 30; i >= 0; i--) {
      int px = (x >> i) & 1, py = (y >> i) & 1;
      if (py) {
        if (Next[now][px] != -1) {
          ans += cnt[Next[now][px]];
        }
        now = Next[now][px ^ 1];
      } else {
        now = Next[now][px];
      }
      if (now == -1) break;
    }
    return ans;
  }
} s;
int main() {
  int q;
  scanf("%d", &q);
  s.init();
  while (q--) {
    int op;
    scanf("%d", &op);
    if (op == 1) {
      int x;
      scanf("%d", &x);
      s.ins(x);
    } else if (op == 2) {
      int x;
      scanf("%d", &x);
      s.del(x);
    } else {
      int x, y;
      scanf("%d%d", &x, &y);
      printf("%d\n", s.query(x, y));
    }
  }
  return 0;
}
