#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int N = 1000005;
const double PI = 4 * atan(1);
const double eps = 1e-7;
long long n, k, t;
long long a[N];
long long x, y;
long long cnt = 0;
struct TrieNode {
  struct TrieNode *children[2];
  bool isEndOfWord;
  long long nb;
};
struct TrieNode *getNode(void) {
  struct TrieNode *pNode = new TrieNode;
  pNode->isEndOfWord = false;
  pNode->nb = 0;
  for (int i = 0; i < 2; i++) {
    pNode->children[i] = NULL;
  }
  return pNode;
}
void insert(struct TrieNode *root, string key) {
  struct TrieNode *pCrawl = root;
  for (int i = 0; i < key.size(); i++) {
    int index = key[i] - '0';
    if (!pCrawl->children[index]) {
      pCrawl->children[index] = getNode();
    }
    pCrawl = pCrawl->children[index];
    pCrawl->nb++;
  }
}
void remove(struct TrieNode *root, string key) {
  struct TrieNode *pCrawl = root;
  for (int i = 0; i < key.size(); i++) {
    int index = key[i] - '0';
    if (!pCrawl->children[index]) {
      pCrawl->children[index] = getNode();
    }
    pCrawl = pCrawl->children[index];
    pCrawl->nb--;
  }
}
bool search(struct TrieNode *root, string key) {
  struct TrieNode *pCrawl = root;
  for (int i = 0; i < key.size(); i++) {
    int index = key[i] - '0';
    if (!pCrawl->children[index]) {
      return false;
    }
    pCrawl = pCrawl->children[index];
  }
  cnt = pCrawl->nb;
  return (pCrawl->nb > 0);
}
int main() {
  ios::sync_with_stdio(0);
  cin >> t;
  struct TrieNode *root = getNode();
  n = 0;
  while (t--) {
    cin >> x >> y;
    if (x == 1) {
      string st = "";
      n++;
      for (int i = 30; i >= 0; i--) {
        if ((1ll << i) & y) {
          st += "1";
        } else
          st += "0";
      }
      insert(root, st);
      continue;
    }
    if (x == 2) {
      n--;
      string st = "";
      for (int i = 30; i >= 0; i--) {
        if ((1ll << i) & y) {
          st += "1";
        } else
          st += "0";
      }
      remove(root, st);
      continue;
    }
    cin >> k;
    string st = "";
    st = "";
    long long ans = 0;
    for (int j = 30; j >= 0; j--) {
      if ((1ll << j) & k) {
        if (j == 0) {
          if (y & (1ll << j)) {
            st += "0";
          } else
            st += "1";
          cnt = 0;
          bool cond = search(root, st);
          ans += cnt;
          continue;
        }
        if (y & (1 << j)) {
          st += "0";
        } else
          st += "1";
        continue;
      }
      cnt = 0;
      if (y & (1ll << j)) {
        bool cond = search(root, st + "0");
      } else {
        bool cond = search(root, st + '1');
      }
      ans += cnt;
      if (y & (1 << j)) {
        st += '1';
      } else {
        st += '0';
      }
      if (j == 0) {
        cnt = 0;
        bool cond = search(root, st);
        ans += cnt;
      }
    }
    cout << n - ans << endl;
  }
  return 0;
}
