#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long maxn = 3e6;
const long long mod = 1e9 + 7;
const long double PI = acos((long double)-1);
long long pw(long long a, long long b, long long md = mod) {
  long long res = 1;
  while (b) {
    if (b & 1) {
      res = (a * res) % md;
    }
    a = (a * a) % md;
    b >>= 1;
  }
  return (res);
}
int ch[maxn][2];
int cnt[maxn][2];
int cur = 0;
int q;
void add(int x) {
  int pos = 0;
  for (int i = 28; i >= 0; i--) {
    int nxt = (x & (1 << i)) > 0;
    if (ch[pos][nxt] != -1) {
      cnt[pos][nxt]++;
      pos = ch[pos][nxt];
    } else {
      ch[pos][nxt] = ++cur;
      cnt[pos][nxt]++;
      pos = ch[pos][nxt];
    }
  }
}
void rm(int x) {
  int pos = 0;
  for (int i = 28; i >= 0; i--) {
    int nxt = (x & (1 << i)) > 0;
    cnt[pos][nxt]--;
    pos = ch[pos][nxt];
  }
}
int solve(int x, int l) {
  int pos = 0;
  int ans = 0;
  for (int i = 28; i >= 0; i--) {
    int tl = (l & (1 << i)) > 0;
    int tx = (x & (1 << i)) > 0;
    if (tx and tl) {
      ans += cnt[pos][1];
      if (cnt[pos][0] == 0) break;
      pos = ch[pos][0];
    }
    if (!tx and !tl) {
      if (cnt[pos][0] == 0) break;
      pos = ch[pos][0];
    }
    if (tx and !tl) {
      if (cnt[pos][1] == 0) break;
      pos = ch[pos][1];
    }
    if (tl and !tx) {
      ans += cnt[pos][0];
      if (cnt[pos][1] == 0) break;
      pos = ch[pos][1];
    }
  }
  return (ans);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> q;
  memset(ch, -1, sizeof ch);
  ;
  while (q--) {
    int t;
    cin >> t;
    if (t == 1) {
      int x;
      cin >> x;
      add(x);
    }
    if (t == 2) {
      int x;
      cin >> x;
      rm(x);
    }
    if (t == 3) {
      int x, l;
      cin >> x >> l;
      cout << solve(x, l) << '\n';
    }
  }
  return (0);
}
