#include "stdafx.h"
#include <iostream>
#include <map>
using namespace std;
int main()
{
int n1;
scanf("%d", &n1);
int i, a;
double b;
map<int, double> m[2];
for(i = 1; i <= n1; i++)
{
scanf("%d%lf", &a, &b);
m[0][a] = b;
}
int n2;
scanf("%d", &n2);
map<int, double> ::reverse_iterator it;
int first;
double second;
for(i = 1; i <= n2; i++)
{
scanf("%d%lf", &a, &b);
for(it = m[0].rbegin(); it != m[0].rend(); it++)
{
first = it->first + a;
second = it->second * b;
m[1][first] += second;
}
}
int count = 0;
for(it = m[1].rbegin(); it != m[1].rend(); it++)
{
second = it->second;
if(second != 0)
{
count++;
}
}
printf("%d", count);
for(it = m[1].rbegin(); it != m[1].rend(); it++)
{
first = it->first;
second = it->second;
if(second != 0)
{
printf(" %d %.1lf", first, second);
}
}
printf("\n");
system("pause");
return 0;
}