#include <bits/stdc++.h>
using namespace std;
const int mx = 100010;
int ch[mx * 32][2];
int cnt[mx * 32];
int sz = 1;
void insert(int k, int val) {
  int u = 0;
  for (int i = 30; i >= 0; i--) {
    int x = ((k >> i) & 1);
    if (ch[u][x] == 0) ch[u][x] = sz++;
    u = ch[u][x];
    cnt[u] += val;
  }
}
int query(int p, int l) {
  int u = 0, ret = 0;
  for (int i = 30; i >= 0; i--) {
    int x = ((p >> i) & 1);
    int y = ((l >> i) & 1);
    if (y) {
      ret += cnt[ch[u][x]];
      if (ch[u][x ^ 1])
        u = ch[u][x ^ 1];
      else
        return ret;
    } else {
      if (ch[u][x])
        u = ch[u][x];
      else
        return ret;
    }
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  while (n--) {
    int a, b, c;
    cin >> a >> b;
    if (a == 1)
      insert(b, 1);
    else if (a == 2)
      insert(b, -1);
    else {
      cin >> c;
      cout << query(b, c) << '\n';
    }
  }
  return 0;
}
