#include<bits/stdc++.h>
using namespace std;
struct node{
int cnt_trees;
node *next[28];
node(){
cnt_trees=0;
for(int i=0;i<28;i++)next[i]=NULL;
}
}*root;
void insert_into_Trie(string str){
node *cur=root;
cur->cnt_trees++;
for(int i=0;str[i];i++){
int id=str[i]-'a';
if(cur->next[id]==NULL)
cur->next[id]=new node();
cur=cur->next[id];
cur->cnt_trees++;
}
}
int search(string str){
node *cur=root;
for(int i=0;str[i];i++){
int id=str[i]-'a';
if(cur->next[id]==NULL) return 0;
cur=cur->next[id];
}
return cur->cnt_trees;
}
int main()
{
int n;
string op,contact;
scanf("%d",&n);
root=new node();
while(n--){
cin>>op>>contact;
if(op=="add")insert_into_Trie(contact);
else if(op=="find"){
cout<<search(contact)<<endl;
}
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKc3RydWN0IG5vZGV7CiAgICBpbnQgY250X3RyZWVzOwogICAgbm9kZSAqbmV4dFsyOF07CiAgICBub2RlKCl7CiAgICAgICAgY250X3RyZWVzPTA7CiAgICAgICAgZm9yKGludCBpPTA7aTwyODtpKyspbmV4dFtpXT1OVUxMOwogICAgfQp9KnJvb3Q7Cgp2b2lkIGluc2VydF9pbnRvX1RyaWUoc3RyaW5nIHN0cil7CiAgICBub2RlICpjdXI9cm9vdDsKICAgIGN1ci0+Y250X3RyZWVzKys7CiAgICBmb3IoaW50IGk9MDtzdHJbaV07aSsrKXsKICAgICAgICBpbnQgaWQ9c3RyW2ldLSdhJzsKICAgICAgICBpZihjdXItPm5leHRbaWRdPT1OVUxMKQogICAgICAgICAgICBjdXItPm5leHRbaWRdPW5ldyBub2RlKCk7CiAgICAgICAgICAgIGN1cj1jdXItPm5leHRbaWRdOwogICAgICAgICAgICBjdXItPmNudF90cmVlcysrOwogICAgfQp9CgppbnQgc2VhcmNoKHN0cmluZyBzdHIpewogICAgbm9kZSAqY3VyPXJvb3Q7CiAgICBmb3IoaW50IGk9MDtzdHJbaV07aSsrKXsKICAgICAgICBpbnQgaWQ9c3RyW2ldLSdhJzsKICAgICAgICBpZihjdXItPm5leHRbaWRdPT1OVUxMKSByZXR1cm4gMDsKICAgICAgICBjdXI9Y3VyLT5uZXh0W2lkXTsKICAgIH0KICAgIHJldHVybiBjdXItPmNudF90cmVlczsKfQoKaW50IG1haW4oKQp7CiAgICBpbnQgbjsKICAgIHN0cmluZyBvcCxjb250YWN0OwogICAgc2NhbmYoIiVkIiwmbik7CiAgICByb290PW5ldyBub2RlKCk7CiAgICB3aGlsZShuLS0pewogICAgICAgY2luPj5vcD4+Y29udGFjdDsKICAgICAgIGlmKG9wPT0iYWRkIilpbnNlcnRfaW50b19UcmllKGNvbnRhY3QpOwogICAgICAgZWxzZSBpZihvcD09ImZpbmQiKXsKICAgICAgICBjb3V0PDxzZWFyY2goY29udGFjdCk8PGVuZGw7CiAgICAgICB9CiAgICB9CiAgICByZXR1cm4gMDsKfQo=