#include <bits/stdc++.h>
using namespace std;
int cnt[6100000];
int tree[6100000][2], sz;
void insert(long long int x) {
  int cur = 0;
  cnt[cur]++;
  for (int i = 60; i > -1; i--) {
    bool bit = (1ll << i) & x;
    if (tree[cur][bit] == -1) tree[cur][bit] = sz++;
    cur = tree[cur][bit];
    cnt[cur]++;
  }
}
void remove(long long int x) {
  int cur = 0;
  cnt[cur]--;
  for (int i = 60; i > -1; i--) {
    bool bit = (1ll << i) & x;
    cur = tree[cur][bit];
    cnt[cur]--;
  }
}
int solve(long long int l, long long int p) {
  int cur = 0, ret = 0;
  for (int i = 60; i > -1; i--) {
    bool bitL = (1ll << i) & l, bitP = (1ll << i) & p;
    bool nextBit = bitL ^ bitP;
    if (bitL && tree[cur][bitP] != -1) {
      ret += cnt[tree[cur][bitP]];
    }
    if (tree[cur][nextBit] == -1) break;
    cur = tree[cur][nextBit];
  }
  return ret;
}
int main() {
  memset(tree, -1, sizeof tree);
  sz = 1;
  int q;
  scanf("%d", &q);
  while (q--) {
    int t;
    long long int p, l;
    scanf("%d%I64d", &t, &p);
    if (t == 1) {
      insert(p);
    } else if (t == 2) {
      remove(p);
    } else {
      scanf("%I64d", &l);
      printf("%d\n", solve(l, p));
    }
  }
  return 0;
}
