![](https://img-blog.csdn.net/20141108091639335?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbHVja2lseXdt/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct F
{
char name[100];
char space[100];
int num;
}f[110];
int cmp(F x,F y)
{
if(strcmp(x.space,y.space))
return strcmp(x.space,y.space)<0;
return strcmp(x.name,y.name)<0;
}
int main()
{
int N,n,i;
scanf("%d",&N);
while(N--)
{
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%s %s %d",f[i].name,f[i].space,&f[i].num);
}
sort(f,f+n,cmp);
char D[100],min[100];
int q=0,r=1;
strcpy(D,f[0].space);
strcpy(min,f[0].name);
for(i=0;i<n;i++)
{
if(strcmp(D,f[i].space))
{
strcpy(D,f[i].space);
strcpy(min,f[i].name);
r=1;
q=0;
}
if(!strcmp(D,f[i].space))
{
if(r)
{
printf("%s\n",D);
r=0;
}
if(!strcmp(min,f[i].name))
{
while(!strcmp(min,f[i].name) && !strcmp(D,f[i].space))
{
q=q+f[i].num;
i++;
}
printf(" |----%s(%d)\n",min,q);
strcpy(min,f[i].name);
i--;
q=0;
}
}
}
if(N)printf("\n");
}
return 0;
}