using namespace std;
class ProductDog;
class CodeMonkey;
class ProductDog
{
string name;
int opt;
public:
int s;
void add_todolist(CodeMonkey& a,int b);
void reduce_todolist(CodeMonkey& a, int b);
void input()
{
cin>>name>>opt>>s;
}
string outname()
{
return name;
}
int outopt()
{
return opt;
}
int outsum()
{
return s;
}
};
class CodeMonkey
{
string name;
int todolist;
public:
CodeMonkey(string a,int b):name(a),todolist(b){}
CodeMonkey();
friend void ProductDog::add_todolist(CodeMonkey&,int);
friend void ProductDog::reduce_todolist(CodeMonkey& , int);
void input()
{
cin>>name>>todolist;
}
string outname()
{
return name;
}
void output()
{
cout<<name<<" "<<todolist<<endl;
}
};
void ProductDog::add_todolist (CodeMonkey& a < int b)
{
a.todolist=a.todolist+b;
}
void ProductDog::reduce_todolist (CodeMonkey& a, int b)
{
a.todolist=a.todolist-b;
}
int main ()
{
CodeMonkey *p;
ProductDog *q;
int m,n,i,j,opt,sum;
string s;
cin>>n;
p=new CodeMonkey [n];
for(i=0;i<n;iPP)
p[i].input() ;
cin>>m;
q=new ProductDog [m];
for(i=0;i<m;iPP)
{
q[i].input() ;
for(j=0;j<n;jPP)
{
if(q[i].outname() ==p[j].outname() &&q[i].outopt() ==1)
q[i].add_todolist(p[j],q[i].outsum() );
else if(q[i].outname() ==p[j].outname() )
q[i].reduce_todolist(p[j],q[i].outsum() );
}
}
for(i=0;i<n;iPP)
{
p[i].output() ;
}
return 0;
}