#include <bits/stdc++.h>
using namespace std;
int tree[3000000];
int node[3000000][2];
int nd;
string tobin(int n) {
  string ans;
  while (n > 0) {
    ans += ('0' + (n % 2));
    n /= 2;
  }
  int l = ans.length();
  for (int i = 1; i <= (27 - l); i++) ans += '0';
  reverse((ans).begin(), (ans).end());
  return ans;
}
void ins(int n) {
  string s = tobin(n);
  int cur = 1;
  tree[cur]++;
  for (int i = 0; i < 27; i++) {
    if (node[cur][s[i] - '0'] == 0) {
      node[cur][s[i] - '0'] = ++nd;
    }
    cur = node[cur][s[i] - '0'];
    tree[cur]++;
  }
}
void del(int n) {
  string s = tobin(n);
  int cur = 1;
  tree[cur]--;
  for (int i = 0; i < 27; i++) {
    if (node[cur][s[i] - '0'] == 0) {
      node[cur][s[i] - '0'] = ++nd;
    }
    cur = node[cur][s[i] - '0'];
    tree[cur]--;
  }
}
int choose(int p, int l) {
  string pp = tobin(p);
  string lp = tobin(l);
  int ans = 0;
  int cur = 1;
  for (int i = 0; i < 27; i++) {
    if (lp[i] == '0') {
      if (node[cur][pp[i] - '0'] == 0) node[cur][pp[i] - '0'] = ++nd;
      cur = node[cur][pp[i] - '0'];
    } else {
      if (pp[i] == '0') {
        ans += tree[node[cur][0]];
        cur = node[cur][1];
      } else {
        ans += tree[node[cur][1]];
        cur = node[cur][0];
      }
    }
  }
  return ans;
}
int main() {
  nd = 1;
  int n = ({
    int a;
    scanf("%d", &a);
    a;
  });
  while (n--) {
    int c = ({
      int a;
      scanf("%d", &a);
      a;
    });
    if (c == 1) {
      int k = ({
        int a;
        scanf("%d", &a);
        a;
      });
      ins(k);
    } else if (c == 2) {
      int k = ({
        int a;
        scanf("%d", &a);
        a;
      });
      del(k);
    } else {
      int p = ({
        int a;
        scanf("%d", &a);
        a;
      }),
          l = ({
            int a;
            scanf("%d", &a);
            a;
          });
      int ans = choose(p, l);
      printf("%d\n", ans);
    }
  }
}
