#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5 + 10;
map<long long, long long> m;
string HHH(long long x) {
  bitset<27> b = x;
  return b.to_string<char, string::traits_type, string::allocator_type>();
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long q;
  cin >> q;
  while (q--) {
    long long op, x, y;
    cin >> op;
    if (op == 3) {
      cin >> x >> y;
      string a = HHH(x), b = HHH(y);
      long long c = 0, i = 0, ans = 0;
      for (int i = 0; i < 27; i++) {
        if (b[i] == '0') {
          c = 2 * c + 1 + (a[i] == '1');
        } else {
          ans += m[2 * c + 1 + (a[i] == '1')];
          c = 2 * c + 1 + (a[i] == '0');
        }
      }
      cout << ans << '\n';
    } else if (op == 1) {
      cin >> x;
      string s = HHH(x);
      long long j = 0;
      for (char i : s) {
        j = 2 * j + 1 + (i - '0');
        m[j]++;
      }
    } else {
      cin >> x;
      string s = HHH(x);
      long long j = 0;
      for (char i : s) {
        j = 2 * j + 1 + (i - '0');
        m[j]--;
      }
    }
  }
  return 0;
}
