#include <bits/stdc++.h>
using namespace std;
struct node {
  node *s[2];
  int num;
  node() {
    memset(s, 0, sizeof(s));
    num = 0;
  }
};
void _insert(node *root, int x) {
  node *p = root;
  for (int i = 31; i >= 0; i--) {
    int t = (x >> i) & 1;
    if (p->s[t] == NULL) p->s[t] = new node;
    p = p->s[t];
    p->num++;
  }
}
void _delete(node *root, int x) {
  node *p = root;
  for (int i = 31; i >= 0; i--) {
    int t = (x >> i) & 1;
    p = p->s[t];
    p->num--;
  }
}
int query(node *root, int x, int y) {
  node *p = root;
  int ans = 0;
  for (int i = 31; i >= 0; i--) {
    int t = (x >> i) & 1, t2 = (y >> i) & 1;
    if (!t2) {
      if (p->s[t] == NULL || p->s[t]->num == 0) return ans;
      p = p->s[t];
    } else {
      if (p->s[t] != NULL) ans += p->s[t]->num;
      if (p->s[t ^ 1] == NULL)
        return ans;
      else
        p = p->s[t ^ 1];
    }
  }
  return ans;
}
int main() {
  int q, x, y, tp;
  node *root;
  root = new node;
  scanf("%d", &q);
  while (q--) {
    scanf("%d", &tp);
    if (tp == 1) {
      scanf("%d", &x);
      _insert(root, x);
    } else if (tp == 2) {
      scanf("%d", &x);
      _delete(root, x);
    } else {
      scanf("%d%d", &x, &y);
      printf("%d\n", query(root, x, y));
    }
  }
  return 0;
}
