#include <bits/stdc++.h>
using namespace std;
struct Node {
  int k;
  pair<int, int> children;
  Node() {
    k = 0;
    children.first = children.second = -1;
  }
};
const int MAXN = 27;
int ans;
vector<Node> trie = {Node()};
vector<bool> p(MAXN), l(MAXN);
void tobin(int x, vector<bool>& kek) {
  for (int i = 0; i < MAXN; ++i) kek[MAXN - i - 1] = x & (1 << i);
}
void add(int val, vector<bool>& path) {
  int cur = 0;
  for (bool i : path) {
    trie[cur].k += val;
    if (!i) {
      if (trie[cur].children.first == -1) {
        trie[cur].children.first = trie.size();
        trie.push_back(Node());
      }
      cur = trie[cur].children.first;
    } else {
      if (trie[cur].children.second == -1) {
        trie[cur].children.second = trie.size();
        trie.push_back(Node());
      }
      cur = trie[cur].children.second;
    }
  }
  trie[cur].k += val;
}
void dfs(int v, int it) {
  if (v == -1 || it >= MAXN) return;
  if (!p[it]) {
    if (!l[it])
      dfs(trie[v].children.first, it + 1);
    else {
      if (trie[v].children.first != -1) ans += trie[trie[v].children.first].k;
      dfs(trie[v].children.second, it + 1);
    }
  } else {
    if (!l[it])
      dfs(trie[v].children.second, it + 1);
    else {
      if (trie[v].children.second != -1) ans += trie[trie[v].children.second].k;
      dfs(trie[v].children.first, it + 1);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  int q;
  cin >> q;
  vector<int> d = {1, -1};
  for (int i = 0; i < q; ++i) {
    int t;
    cin >> t;
    if (t <= 2) {
      int x;
      cin >> x;
      tobin(x, p);
      add(d[t - 1], p);
    } else {
      int l1, p1;
      cin >> p1 >> l1;
      tobin(l1, l);
      tobin(p1, p);
      ans = 0;
      dfs(0, 0);
      cout << ans << '\n';
    }
  }
  return 0;
}
