#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
struct Trie {
  int son[N * 27][2], sz[N * 27];
  int alloc, rt;
  int newnode() {
    ++alloc;
    son[alloc][0] = son[alloc][1] = 0;
    sz[alloc] = 0;
    return alloc;
  }
  void init() {
    son[0][0] = son[0][1] = 0;
    sz[0] = 0;
    alloc = 0;
    rt = newnode();
  }
  void insert(int x) {
    int p = rt;
    for (int i = 26; i >= 0; --i) {
      int nx = (x >> i) & 1;
      if (son[p][nx] == 0) son[p][nx] = newnode();
      p = son[p][nx];
      sz[p]++;
    }
  }
  void del(int x) {
    int p = rt;
    for (int i = 26; i >= 0; --i) {
      int nx = (x >> i) & 1;
      if (son[p][nx] == 0) son[p][nx] = newnode();
      p = son[p][nx];
      sz[p]--;
    }
  }
  int query(int v, int x) {
    int p = rt, res = 0;
    for (int i = 26; i >= 0; --i) {
      int nv = (v >> i) & 1, nx = (x >> i) & 1;
      if (nv == 1 && nx == 0) {
        p = son[p][1];
      } else if (nv == 0 && nx == 1) {
        res += sz[son[p][0]];
        p = son[p][1];
      } else if (nv == 0 && nx == 0) {
        p = son[p][0];
      }
      if (nv == 1 && nx == 1) {
        res += sz[son[p][1]];
        p = son[p][0];
      }
    }
    return res;
  }
} trie;
int main() {
  trie.init();
  int n, t, x, y;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &t);
    if (t == 1) {
      scanf("%d", &x);
      trie.insert(x);
    } else if (t == 2) {
      scanf("%d", &x);
      trie.del(x);
    } else {
      scanf("%d %d", &x, &y);
      int ans = trie.query(x, y);
      printf("%d\n", ans);
    }
  }
}
