#include <bits/stdc++.h>
using namespace std;
const int N = 1e7 + 5;
int kc;
int newNode() { return ++kc; }
int st[N], ch[N][2];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int q;
  cin >> q;
  int root = newNode();
  while (q--) {
    int t, p;
    cin >> t >> p;
    if (t == 3) {
      int l;
      cin >> l;
      p ^= l;
      int ans = 0;
      int troot = root;
      for (int i = 29; i >= 0 and troot; i--) {
        bool bp = p & (1 << i);
        bool bl = l & (1 << i);
        if (bl) ans += st[ch[troot][1 - bp]];
        troot = ch[troot][bp];
      }
      cout << ans << "\n";
    } else {
      int ad = 1;
      if (t == 2) ad = -1;
      int troot = root;
      for (int i = 29; i >= 0; i--) {
        st[troot] += ad;
        bool b = p & (1 << i);
        if (ch[troot][b] == 0) ch[troot][b] = newNode();
        troot = ch[troot][b];
      }
      st[troot] += ad;
    }
  }
  return 0;
}
