#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int const N = 1000 * 1000 + 16;
int const M = 1000 * 1000 * 1000 + 7;
struct node {
  int cnt = 0;
  node* k[2] = {};
  ~node() {
    delete k[0];
    delete k[1];
  }
};
struct trie {
  node* root = new node;
  ~trie() { delete root; }
  void insert(int x) {
    auto p = root;
    for (int i = 26; i >= 0; --i) {
      int b = (x >> i) & 1;
      if (not p->k[b]) p->k[b] = new node;
      p = p->k[b];
      p->cnt++;
    }
  }
  void remove(int x) {
    auto p = root;
    for (int i = 26; i >= 0; --i) {
      p = p->k[(x >> i) & 1];
      p->cnt--;
    }
  }
  int query(int x, int l) {
    int ans = 0;
    auto p = root;
    for (int i = 26; i >= 0; --i) {
      int b = (x >> i) & 1;
      int c = (l >> i) & 1;
      if (c == 0) {
        if (p->k[b] && p->k[b]->cnt) {
          p = p->k[b];
        } else {
          break;
        }
      } else {
        if (p->k[b] && p->k[b]->cnt) ans += p->k[b]->cnt;
        if (p->k[b ^ 1] && p->k[b ^ 1])
          p = p->k[b ^ 1];
        else
          break;
      }
    }
    return ans;
  }
};
int q;
int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  cin >> q;
  trie t;
  while (q--) {
    int c, p;
    cin >> c >> p;
    if (c == 1)
      t.insert(p);
    else if (c == 2)
      t.remove(p);
    else {
      int l;
      cin >> l;
      cout << t.query(p, l) << "\n";
    }
  }
}
