#include <iostream>
using namespace std;
int main() {
double a, ans[1001] = { 0 };
int k,n,count = 0;
cin >> k;
for (int i = 0; i < k; i++) {
cin >> n >> a;
count++;
ans[n] = a;
}
cin >> k;
for (int i= 0; i < k; i++) {
cin >> n >> a;
if (ans[n] == 0)
count++;
ans[n] += a;
if (ans[n] == 0)
count--;
}
cout << count;
for(int i=1000;i>=0;i--)
if(ans[i])
printf(" %d %.1f",i,ans[i]);
}