#include <iostream>
#include <stdio.h>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
int sum[101]={0};
int s,n;
for(int i=1; i<=2; i++)
{
while(cin>>s)
{
if(s==-1) break;
cin>>n;
sum[s]+=n;
}
}
for(int i=0; i<=100; i++)
{
if(sum[i]==0) continue;
else cout<<i<<' '<<sum[i]<<endl;
}
}