#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
struct Trie {
  const static int ALPHA_SIZE = 2;
  char base = 'a';
  vector<vector<int> > g;
  vector<int> pref, words;
  int nxt = 1;
  int move_to(int u, int c) {
    if (g[u][c] == -1) {
      g[u][c] = nxt++;
      g.push_back(vector<int>(ALPHA_SIZE, -1));
      pref.push_back(0);
      words.push_back(0);
    }
    pref[g[u][c]]++;
    return g[u][c];
  }

 public:
  Trie() {
    g.push_back(vector<int>(ALPHA_SIZE, -1));
    pref.push_back(0);
    words.push_back(0);
  }
  void addBit(int a) {
    int u = 0;
    for (int i = 30; i >= 0; i--) u = move_to(u, bool(a & (1ll << i)));
    words[u]++;
  }
  int query(int p, int l) {
    int u = 0;
    int ans = 0;
    for (int i = 30; i >= 0 && u != -1; i--) {
      int pi = bool((1 << i) & p);
      int li = bool((1 << i) & l);
      if (li) {
        if (pi) {
          if (g[u][1] != -1) ans += pref[g[u][1]];
          u = g[u][0];
        } else {
          if (g[u][0] != -1) ans += pref[g[u][0]];
          u = g[u][1];
        }
      } else {
        if (pi)
          u = g[u][1];
        else
          u = g[u][0];
      }
    }
    return ans;
  }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  Trie trieAll = Trie();
  Trie trieErased = Trie();
  for (int i = 0; i < q; ++i) {
    int t, p, l;
    cin >> t >> p;
    if (t == 1) {
      trieAll.addBit(p);
    } else if (t == 2) {
      trieErased.addBit(p);
    } else {
      cin >> l;
      int q1 = trieAll.query(p, l);
      int q2 = trieErased.query(p, l);
      cout << q1 - q2 << "\n";
    }
  }
}
