#include <iostream>
#include<map>
#include<iomanip>
#include<stdio.h>
using namespace std;
int main()
{
map<int,double> polynomial;
int n,input1;
double input2;
scanf("%d",&n);
for (int i=0;i<n ;i++ ){
cin>>input1>>input2;
polynomial[input1]=input2;
}
scanf("%d",&n);
for (int i=0;i<n ;i++ ){
cin>>input1>>input2;
if(polynomial.find(input1)==polynomial.end()){//
represent try to find n in s,but not found situation.
polynomial[input1]=input2;
}
else{
polynomial[input1]=polynomial[input1]+input2;
}
if(polynomial[input1]==0)
polynomial.erase(input1);
}
map<int,double>::reverse_iterator i;//can use auto instead
cout<<polynomial.size();
for (i=polynomial.rbegin();i!=polynomial.rend();i++){
cout<<" "<<i->first<<" "<<fixed<<setprecision(1)<<i->second;