#include <bits/stdc++.h>
using namespace std;
long long ch[30 * 100005][2], cnt[30 * 100005], m = 27, num = 1;
void solve1() {
  long long t;
  cin >> t;
  long long now = 1;
  vector<long long> v;
  for (long long i = 0; i <= m; i++) {
    v.emplace_back(now);
    long long to = ((1 << (m - i)) & t) > 0;
    if (!ch[now][to]) {
      ch[now][to] = ++num;
    }
    now = ch[now][to];
  }
  cnt[now]++;
  for (auto u : v) cnt[u]++;
}
void solve2() {
  long long t;
  cin >> t;
  long long now = 1;
  vector<long long> v;
  for (long long i = 0; i <= m; i++) {
    v.emplace_back(now);
    long long to = ((1 << (m - i)) & t) > 0;
    now = ch[now][to];
  }
  cnt[now]--;
  for (auto u : v) cnt[u]--;
}
void solve3() {
  long long t, s;
  cin >> t >> s;
  long long now = 1, ans = 0;
  for (long long i = 0; i <= m; i++) {
    long long to = ((1 << (m - i)) & t) > 0, so = ((1 << (m - i)) & s) > 0;
    if (so) {
      ans += cnt[ch[now][to]];
    }
    now = ch[now][to ^ so];
    if (now == 0) break;
  }
  cout << ans << '\n';
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long _;
  cin >> _;
  while (_--) {
    long long t;
    cin >> t;
    if (t == 1) {
      solve1();
    } else if (t == 2) {
      solve2();
    } else {
      solve3();
    }
  }
  return 0;
}
