#include <bits/stdc++.h>
using namespace std;
int n, w, Q, x, y, z;
int L[3200005], R[3200005], cnt[3200005];
int bits[34], tar[34];
int ans;
void to_binary(int X) {
  int x = X, y = 0;
  for (int i = (30); i >= (0); i--) {
    y = (1 << i);
    if (x >= y)
      bits[i] = 1;
    else
      bits[i] = 0;
    x %= y;
  }
}
void insert(int x, int y, int val) {
  if (y < 0) {
    cnt[x] += val;
    return;
  }
  if (bits[y] == 1) {
    if (R[x] == 0) R[x] = ++w;
    insert(R[x], y - 1, val);
  } else if (bits[y] == 0) {
    if (L[x] == 0) L[x] = ++w;
    insert(L[x], y - 1, val);
  }
  cnt[x] += val;
}
void query(int x, int y) {
  if (tar[y] == 1) {
    if (bits[y] == 0 && L[x] != 0) ans += cnt[L[x]];
    if (bits[y] == 1 && R[x] != 0) ans += cnt[R[x]];
    if (bits[y] == 0 && R[x] != 0) query(R[x], y - 1);
    if (bits[y] == 1 && L[x] != 0) query(L[x], y - 1);
  } else {
    if (bits[y] == 0 && L[x] != 0) query(L[x], y - 1);
    if (bits[y] == 1 && R[x] != 0) query(R[x], y - 1);
  }
}
int main() {
  scanf("%d", &n);
  while (n--) {
    scanf("%d %d", &Q, &x);
    to_binary(x);
    if (Q == 1)
      insert(0, 30, 1);
    else if (Q == 2)
      insert(0, 30, -1);
    else {
      scanf("%d", &y);
      to_binary(y);
      for (int i = (0); i < (31); i++) tar[i] = bits[i];
      to_binary(x);
      ans = 0;
      query(0, 30);
      printf("%d\n", ans);
    }
  }
  return 0;
}
