#include <bits/stdc++.h>
using namespace std;
int n, t, x, y, num;
int nxt[5000005][2], cnt[5000005];
int a[50], b[50];
void ins(int x) {
  for (int i = 30; i >= 0; --i) a[i] = (x >> i) & 1;
  int dq = 0;
  for (int i = 30; i >= 0; --i) {
    cnt[dq]++;
    if (nxt[dq][a[i]] == 0) {
      ++num;
      nxt[dq][a[i]] = num;
    }
    dq = nxt[dq][a[i]];
  }
  cnt[dq]++;
}
void del(int x) {
  for (int i = 30; i >= 0; --i) a[i] = (x >> i) & 1;
  int dq = 0;
  for (int i = 30; i >= 0; --i) {
    cnt[dq]--;
    dq = nxt[dq][a[i]];
  }
  cnt[dq]--;
}
int query(int x, int y) {
  for (int i = 30; i >= 0; --i) a[i] = (x >> i) & 1;
  for (int i = 30; i >= 0; --i) b[i] = (y >> i) & 1;
  int dq = 0, ans = 0;
  for (int i = 30; i >= 0; --i) {
    if (b[i] == 1) {
      if (nxt[dq][a[i]] != 0) ans += cnt[nxt[dq][a[i]]];
    }
    dq = nxt[dq][a[i] ^ b[i]];
    if (dq == 0) break;
  }
  return ans;
}
int main() {
  scanf("%d", &n);
  num = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &t);
    if (t == 1) {
      scanf("%d", &x);
      ins(x);
    } else if (t == 2) {
      scanf("%d", &x);
      del(x);
    } else if (t == 3) {
      scanf("%d%d", &x, &y);
      printf("%d\n", query(x, y));
    }
  }
  return 0;
}
