#include <bits/stdc++.h>
using namespace std;
long long int dp[2][100005];
struct trie {
  trie *a[2];
  long long int val;
  trie() {
    a[0] = NULL;
    a[1] = NULL;
    val = 0;
  }
};
void insert(trie *root, long long int s, long long int sum) {
  trie *temp = root;
  for (long long int i = 31; i >= 0; --i) {
    bool ind = s & (1 << i);
    if (temp->a[ind] == NULL) temp->a[ind] = new trie();
    temp->a[ind]->val += sum;
    temp = temp->a[ind];
  }
}
long long int query(trie *root, long long int p, long long int l) {
  trie *temp = root;
  long long int ans = 0;
  for (long long int i = 31; i >= 0; --i) {
    bool ind = p & (1 << i), req = l & (1 << i);
    if (temp->a[0] == NULL) temp->a[0] = new trie();
    if (temp->a[1] == NULL) temp->a[1] = new trie();
    if (ind && req) {
      ans = ans + temp->a[1]->val;
      temp = temp->a[0];
    }
    if (ind && (!req)) {
      temp = temp->a[1];
    }
    if ((!ind) && req) {
      ans = ans + temp->a[0]->val;
      temp = temp->a[1];
    }
    if ((!ind) && (!req)) {
      temp = temp->a[0];
    }
  }
  return ans;
}
int main() {
  long long int n, i, r = 0;
  cin >> n;
  trie *root = new trie();
  insert(root, 0, 0);
  for (i = 0; i < n; ++i) {
    long long int t, p;
    cin >> t >> p;
    if (t == 1) insert(root, p, 1);
    if (t == 2) insert(root, p, -1);
    if (t == 3) {
      long long int l;
      cin >> l;
      cout << query(root, p, l) << "\n";
    }
  }
  return 0;
}
