/*
Copyright 2012 Marek "p2004a" Rusinowski
Trie tree
*/
#include <cstdio>
class Trie {
Trie *son[26];
char num;
bool end;
public:
Trie() : num(0), end(false) {
for (int i = 0; i < 26; ++i) {
son[i] = NULL;
}
}
~Trie() {
for (int i = 0; i < 26; ++i) {
if (son[i] != NULL) delete son[i];
}
}
#define x son[*c - 'a']
void add(char *c) {
if (*c == '\0') {
end = true;
return;
}
if (x == NULL) {
x = new Trie;
++num;
}
x->add(c + 1);
}
bool query(char *c) {
if (*c == '\0') return end;
return x != NULL && x->query(c + 1);
}
bool erase(char *c) {
if (*c == '\0') {
bool tmp = end;
end = false;
return tmp;
}
if (x != NULL && x->erase(c + 1) && x->num == 0 && x->end == false) {
delete x;
x = NULL;
--num;
return true;
}
return false;
}
#undef x
};
char str[1000000];
int main() {
int n;
char c;
scanf("%d\n", &n);
Trie tree;
while (n--) {
scanf("%c %s\n", &c, str);
switch (c) {
case 'a':
tree.add(str);
printf("add\n");
break;
case 'q':
printf(tree.query(str) ? "true\n" : "false\n");
break;
case 'e':
tree.erase(str);
break;
}
}
return 0;
}
LyoKICBDb3B5cmlnaHQgMjAxMiBNYXJlayAicDIwMDRhIiBSdXNpbm93c2tpCiAgVHJpZSB0cmVlCiovCiNpbmNsdWRlIDxjc3RkaW8+CgpjbGFzcyBUcmllIHsKICBUcmllICpzb25bMjZdOwogIGNoYXIgbnVtOwogIGJvb2wgZW5kOwogIAogcHVibGljOgogIFRyaWUoKSA6IG51bSgwKSwgZW5kKGZhbHNlKSB7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IDI2OyArK2kpIHsKICAgICAgc29uW2ldID0gTlVMTDsKICAgIH0KICB9CiAgCiAgflRyaWUoKSB7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IDI2OyArK2kpIHsKICAgICAgaWYgKHNvbltpXSAhPSBOVUxMKSBkZWxldGUgc29uW2ldOwogICAgfQogIH0KICAKICAjZGVmaW5lIHggc29uWypjIC0gJ2EnXQogIAogIHZvaWQgYWRkKGNoYXIgKmMpIHsKICAgIGlmICgqYyA9PSAnXDAnKSB7CiAgICAgIGVuZCA9IHRydWU7CiAgICAgIHJldHVybjsKICAgIH0KICAgIGlmICh4ID09IE5VTEwpIHsKICAgICAgeCA9IG5ldyBUcmllOwogICAgICArK251bTsKICAgIH0KICAgIHgtPmFkZChjICsgMSk7CiAgfQogIAogIGJvb2wgcXVlcnkoY2hhciAqYykgewogICAgaWYgKCpjID09ICdcMCcpIHJldHVybiBlbmQ7CiAgICByZXR1cm4geCAhPSBOVUxMICYmIHgtPnF1ZXJ5KGMgKyAxKTsKICB9CiAgCiAgYm9vbCBlcmFzZShjaGFyICpjKSB7CiAgICBpZiAoKmMgPT0gJ1wwJykgewogICAgICBib29sIHRtcCA9IGVuZDsKICAgICAgZW5kID0gZmFsc2U7CiAgICAgIHJldHVybiB0bXA7CiAgICB9CiAgICBpZiAoeCAhPSBOVUxMICYmIHgtPmVyYXNlKGMgKyAxKSAmJiB4LT5udW0gPT0gMCAmJiB4LT5lbmQgPT0gZmFsc2UpIHsKICAgICAgZGVsZXRlIHg7CiAgICAgIHggPSBOVUxMOwogICAgICAtLW51bTsKICAgICAgcmV0dXJuIHRydWU7CiAgICB9CiAgICByZXR1cm4gZmFsc2U7CiAgfQogIAogICN1bmRlZiB4Cn07CgpjaGFyIHN0clsxMDAwMDAwXTsKCmludCBtYWluKCkgewogIGludCBuOwogIGNoYXIgYzsKICBzY2FuZigiJWRcbiIsICZuKTsKICBUcmllIHRyZWU7CiAgd2hpbGUgKG4tLSkgewogICAgc2NhbmYoIiVjICVzXG4iLCAmYywgc3RyKTsKICAgIHN3aXRjaCAoYykgewogICAgICBjYXNlICdhJzoKICAgICAgICB0cmVlLmFkZChzdHIpOwogICAgICAgIHByaW50ZigiYWRkXG4iKTsKICAgICAgICBicmVhazsKICAgICAgY2FzZSAncSc6CiAgICAgICAgcHJpbnRmKHRyZWUucXVlcnkoc3RyKSA/ICJ0cnVlXG4iIDogImZhbHNlXG4iKTsKICAgICAgICBicmVhazsKICAgICAgY2FzZSAnZSc6CiAgICAgICAgdHJlZS5lcmFzZShzdHIpOwogICAgICAgIGJyZWFrOwogICAgfQogIH0KICByZXR1cm4gMDsKfQo=