#include <bits/stdc++.h>
using namespace std;
const int N = 102;
const int mod = 1000000007;
const int inf = mod;
inline void scan(int &x) {
  register int c = getchar();
  x = 0;
  for (; (c < 48 || c > 57); c = getchar())
    ;
  for (; c > 47 && c < 58; c = getchar()) {
    x = (x << 1) + (x << 3) + c - 48;
  }
}
int n, m, t, b, k, x;
void multiply(int a[][N], int b[][N]) {
  int mul[n][n];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int res = mul[i][j];
      for (int k = 0; k < n; k++) {
        res = (res + (a[i][k] * b[k][j])) % x;
      }
      mul[i][j] = res;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      a[i][j] = mul[i][j];
    }
  }
}
void matrix_expo(int f, int a[][N], int r[][N]) {
  cout << f << endl;
  while (f) {
    if (f & 1) {
      multiply(r, a);
    }
    multiply(a, a);
    f >>= 1;
  }
}
struct node {
  node *next[2];
  int cnt;
  node() {
    cnt = 0;
    for (int i = 0; i < 2; i++) {
      next[i] = NULL;
    }
  }
} * root;
int buf = 30;
void upd(int val, int num) {
  node *cur = root;
  for (int i = buf; i >= 0; i--) {
    int id = (val & (1ll << i)) >> i;
    if (cur->next[id] == NULL) {
      cur->next[id] = new node();
    }
    cur = cur->next[id];
    cur->cnt = num + (cur->cnt);
  }
}
int query(int val, int controller) {
  node *cur = root;
  int ans = 0;
  for (int i = buf; i >= 0; i--) {
    int id = (val & (1ll << i)) >> i;
    int controlId = (controller & (1ll << i)) >> i;
    if (controlId) {
      if (cur->next[!id]) {
        if (cur->next[id]) {
          ans += (cur->next[id]->cnt);
        }
        cur = cur->next[!id];
      } else {
        if (cur->next[id]) {
          ans += (cur->next[id]->cnt);
        }
        break;
      }
    } else {
      if (cur->next[id]) {
        cur = cur->next[id];
      } else {
        break;
      }
    }
  }
  return ans;
}
int main() {
  int t;
  cin >> t;
  root = new node();
  while (t--) {
    int type;
    scanf("%d%d", &type, &n);
    if (type == 1) {
      upd(n, 1);
    } else if (type == 2) {
      upd(n, -1);
    } else {
      int l;
      scanf("%d", &l);
      int ret = query(n, l);
      printf("%d\n", ret);
    }
  }
  return 0;
}
