#include <bits/stdc++.h>
using namespace std;
const int maxnode = 1e5 * 32 + 5;
int ch[maxnode][2], val[maxnode], sz;
void Insert(int x) {
  int u = 0;
  for (int i = 31; i >= 0; i--) {
    int idx = (x >> i) & 1;
    if (!ch[u][idx]) ch[u][idx] = ++sz;
    u = ch[u][idx];
    val[u]++;
  }
}
void Delete(int x) {
  int u = 0;
  for (int i = 31; i >= 0; i--) {
    int idx = (x >> i) & 1;
    u = ch[u][idx];
    val[u]--;
  }
}
int Match(int x, int y) {
  int u = 0, ans = 0;
  for (int i = 31; i >= 0; i--) {
    int idxx = (x >> i) & 1;
    int idxy = (y >> i) & 1;
    if (!idxy) {
      if (!ch[u][idxx]) break;
      u = ch[u][idxx];
    } else {
      if (ch[u][idxx]) ans += val[ch[u][idxx]];
      if (!ch[u][!idxx]) break;
      u = ch[u][!idxx];
    }
  }
  return ans;
}
int main() {
  int q;
  cin >> q;
  while (q--) {
    int cmd, x, y;
    scanf("%d%d", &cmd, &x);
    if (cmd == 1)
      Insert(x);
    else if (cmd == 2)
      Delete(x);
    else {
      scanf("%d", &y);
      printf("%d\n", Match(x, y));
    }
  }
  return 0;
}
