#include <bits/stdc++.h>
int read() {
  static int ch, x;
  while (isspace(ch = getchar())) {
  }
  x = ch ^ 48;
  while (isdigit(ch = getchar())) x = (((x << 2) + x) << 1) + (ch ^ 48);
  return x;
}
const int rt = 1;
int tot = 1;
int sum[100010 * 32];
int ch[100010 * 32][2];
void insert(int x) {
  int p = rt;
  for (int i = 31; ~i; --i) {
    const int w = (x >> i) & 1;
    if (!ch[p][w]) ch[p][w] = ++tot;
    p = ch[p][w];
    ++sum[p];
  }
}
void erase(int x) {
  int p = rt;
  for (int i = 31; ~i; --i) {
    p = ch[p][(x >> i) & 1];
    --sum[p];
  }
}
int query(int x, const int l) {
  int p = rt, ans = 0;
  for (int i = 31; ~i; --i) {
    const int w = (x >> i) & 1;
    if ((l >> i) & 1) {
      ans += sum[ch[p][w]];
      p = ch[p][w ^ 1];
    } else {
      p = ch[p][w];
    }
  }
  return ans;
}
int main() {
  for (int q = read(); q--;) {
    switch (read()) {
      case 1: {
        insert(read());
        break;
      }
      case 2: {
        erase(read());
        break;
      }
      case 3: {
        const int x = read();
        printf("%d\n", query(x, read()));
        break;
      }
      default:
        assert(false);
    }
  }
  return 0;
}
