#include <bits/stdc++.h>
using namespace std;
#define mt make_tuple
#define mkp make_pair
#define pb push_back
#define pii pair<ll,ll>
#define pss pair<int,int>
#define pdd pair<double,double>
#define pldd pair<ld,ld>
#define pff pair<float,float>
#define piii pair<ll, pair<ll,ll> >
#define pddd pair<ld, pair<ld,ld> >
#define ff first
#define ss second
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
const int N = (1 << 16);
int getBits(int s) {
int ans = 0;
for(int i = 0; i < 16; i++)
if((s & (1 << i)) != 0)
ans++;
return ans;
}
int main() {
int ms[N];
int osob[N];
int q;
cin >> q;
while(q--) {
string c;
int s;
cin >> c >> s;
int bits = getBits(s);
if(c == "add" || c == "del") {
int d = 1;
if(c == "del") d = -1;
ms[s] += d;
if(bits <= 16) {
osob[N - 1] += d;
}
} else {
int ans = 0;
if(bits >= 16) {
ans = osob[s];
} else {
for(int ss = s; ; ss = (ss - 1) & s) {
ans += ms[ss];
if(ss == 0) break;
}
}
cout << ans << endl;
}
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgojZGVmaW5lIG10IG1ha2VfdHVwbGUKI2RlZmluZSBta3AgbWFrZV9wYWlyCiNkZWZpbmUgcGIgcHVzaF9iYWNrCiNkZWZpbmUgcGlpIHBhaXI8bGwsbGw+CiNkZWZpbmUgcHNzIHBhaXI8aW50LGludD4KI2RlZmluZSBwZGQgcGFpcjxkb3VibGUsZG91YmxlPgojZGVmaW5lIHBsZGQgcGFpcjxsZCxsZD4KI2RlZmluZSBwZmYgcGFpcjxmbG9hdCxmbG9hdD4KI2RlZmluZSBwaWlpIHBhaXI8bGwsIHBhaXI8bGwsbGw+ID4KI2RlZmluZSBwZGRkIHBhaXI8bGQsIHBhaXI8bGQsbGQ+ID4KI2RlZmluZSBmZiBmaXJzdAojZGVmaW5lIHNzIHNlY29uZAp0eXBlZGVmIGxvbmcgbG9uZyBpbnQgbGw7CnR5cGVkZWYgdW5zaWduZWQgbG9uZyBsb25nIGludCB1bGw7CnR5cGVkZWYgbG9uZyBkb3VibGUgbGQ7CgoKCgpjb25zdCBpbnQgTiA9ICgxIDw8IDE2KTsKCmludCBnZXRCaXRzKGludCBzKSB7CiAgICBpbnQgYW5zID0gMDsKICAgIGZvcihpbnQgaSA9IDA7IGkgPCAxNjsgaSsrKQogICAgICAgIGlmKChzICYgKDEgPDwgaSkpICE9IDApCiAgICAgICAgICAgIGFucysrOwogICAgcmV0dXJuIGFuczsKfQoKaW50IG1haW4oKSB7CiAgICBpbnQgbXNbTl07CiAgICBpbnQgb3NvYltOXTsKCiAgICBpbnQgcTsKICAgIGNpbiA+PiBxOwogICAgd2hpbGUocS0tKSB7CiAgICAgICAgc3RyaW5nIGM7CiAgICAgICAgaW50IHM7CiAgICAgICAgY2luID4+IGMgPj4gczsKCiAgICAgICAgaW50IGJpdHMgPSBnZXRCaXRzKHMpOwoKICAgICAgICBpZihjID09ICJhZGQiIHx8IGMgPT0gImRlbCIpIHsKICAgICAgICAgICAgaW50IGQgPSAxOwogICAgICAgICAgICBpZihjID09ICJkZWwiKSBkID0gLTE7CiAgICAgICAgICAgIG1zW3NdICs9IGQ7CiAgICAgICAgICAgIGlmKGJpdHMgPD0gMTYpIHsKICAgICAgICAgICAgICAgIG9zb2JbTiAtIDFdICs9IGQ7CiAgICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBpbnQgYW5zID0gMDsKICAgICAgICAgICAgaWYoYml0cyA+PSAxNikgewogICAgICAgICAgICAgICAgYW5zID0gb3NvYltzXTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIGZvcihpbnQgc3MgPSBzOyA7IHNzID0gKHNzIC0gMSkgJiBzKSB7CiAgICAgICAgICAgICAgICAgICAgYW5zICs9IG1zW3NzXTsKICAgICAgICAgICAgICAgICAgICBpZihzcyA9PSAwKSBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBjb3V0IDw8IGFucyA8PCBlbmRsOwogICAgICAgIH0KICAgIH0KfQoKCg==