#include <bits/stdc++.h>
using namespace std;
const int M = 4e6 + 10;
int ta[M][3], sum[M], len;
void Tinsert(int x) {
  int num[31];
  memset(num, 0, sizeof(num));
  int flag = 0;
  while (x) {
    num[flag++] = x % 2;
    x /= 2;
  }
  int u = 0, n = 29;
  for (int i = n; i >= 0; i--) {
    if (!ta[u][num[i]]) ta[u][num[i]] = ++len;
    u = ta[u][num[i]];
    sum[u]++;
  }
}
void Tdel(int x) {
  int num[31];
  memset(num, 0, sizeof(num));
  int flag = 0;
  while (x) {
    num[flag++] = x % 2;
    x /= 2;
  }
  int u = 0, n = 29;
  for (int i = n; i >= 0; i--) {
    if (!ta[u][num[i]]) ta[u][num[i]] = ++len;
    u = ta[u][num[i]];
    sum[u]--;
  }
}
int getans(int x, int z) {
  int num[31], flag = 0;
  memset(num, 0, sizeof(num));
  while (x) {
    num[flag++] = x % 2;
    x /= 2;
  }
  int l[31];
  flag = 0;
  memset(l, 0, sizeof(l));
  while (z) {
    l[flag++] = z % 2;
    z /= 2;
  }
  int u = 0, n = 29;
  int ans = 0;
  for (int i = n; i >= 0; i--) {
    if (l[i] == 0) {
      if (!ta[u][num[i]]) break;
      u = ta[u][num[i]];
    } else {
      if (ta[u][num[i]]) ans += sum[ta[u][num[i]]];
      if (!ta[u][!num[i]]) break;
      u = ta[u][!num[i]];
    }
  }
  return ans;
}
int main() {
  int q;
  scanf("%d", &q);
  while (q--) {
    int t, p;
    scanf("%d%d", &t, &p);
    if (t == 1)
      Tinsert(p);
    else if (t == 2)
      Tdel(p);
    else {
      int x;
      scanf("%d", &x);
      printf("%d\n", getans(p, x));
    }
  }
  return 0;
}
