#include<iostream>
#include<string>
#include<map>
using namespace std;
int main()
{
int n,i,c;
string a,b;
map<string ,map<string,int> >maps;
cin>>n;
for(i=0;i<n;++i)
{
cin>>a>>b>>c;
maps[b][a] += c;
}
for(map<string,map<string,int> >::iterator iter = maps.begin();iter !=maps.end();++iter)
{
cout<<iter->first<<endl;
for(map<string,int>::iterator iter_2 = (iter->second).begin();iter_2 != (iter->second).end();iter_2++)
{
cout<<" "<<"|----"
<<iter_2->first<<"("<<iter_2->second<<")"<<endl;
}
}
return 0;
}