#include <bits/stdc++.h>
using namespace std;
int a[30 * 100005][2], p, num[60 * 100005];
void add(int n, int mark) {
  int s = 0;
  for (int i = 29; i >= 0; i--) {
    int x = (n >> i) & 1;
    if (a[s][x] == 0) {
      a[s][x] = ++p;
    }
    s = a[s][x];
    num[s] += mark;
  }
}
int out(int n, int m) {
  int s = 0, ans = 0;
  for (int i = 29; i >= 0; i--) {
    int x = (n >> i) & 1, y = (m >> i) & 1;
    if (y) {
      if (a[s][x] != 0) {
        ans += num[a[s][x]];
      }
    }
    s = a[s][x ^ y];
    if (s == 0) break;
  }
  return ans;
}
int main() {
  int n, op, x, y;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &op);
    if (op < 3) {
      scanf("%d", &x);
      add(x, ((op - 1) * -2) + 1);
    } else {
      scanf("%d%d", &x, &y);
      printf("%d\n", out(x, y));
    }
  }
}
