//论stl的重要性
#include<bits/stdc++.h>
using namespace std;
//char str[100010];
string str;
map<string,int> mp;
int main()
{
int n;
cin>>n;
while(n--)
{
char op[2];
cin>>op>>str;
if(op[0]=='I')
{
++mp[str];
}
else{
bool flag=false;
for(map<string,int>::iterator it=mp.begin();it!=mp.end();it++)
{
if(str== it->first)
{
flag=true;
cout<<mp[str]<<endl;
}
}
if(!flag)
{
cout<<0<<endl;
}
}
}
}