using namespace std;
#include<iostream>
#include<map>
#include<string>
int main(){
int n;
cin>>n;
map<string,map<string,int> > T;
for(int i=0;i<n;i++){
string fruit,place;
int num;
cin>>fruit>>place;
cin>>num;
if(!T[place].count(fruit)){
map<string,int> f;
T[place][fruit]+=num;
}
}
map<string,map<string,int> >::iterator it;
for(it =T.begin();it!=T.end();it++){
cout<<it->first<<endl;
for(map<string,int>::iterator itt=it->second.begin();itt!=it->second.end();itt++)
cout<<" |----"<<itt->first<<"("<<itt->second<<")"<<endl;
}
return 0;
}