#include <iostream>
#include <cstdio>
using namespace std;
typedef struct nodee
{
int n = 0;
double a = 0;
nodee *next = NULL;
} node;
int main()
{
int m, n;
cin >> m;
node *pm = new node;
node *pn = new node;
for (int i = 0; i < m; i++)
{
int x;
double y;
cin >> x >> y;
node *p = new node;
p->a = y;
p->n = x;
p->next = pm->next;
pm->next = p;
p = NULL;
delete p;
}
cin >> n;
for (int i = 0; i < n; i++)
{
int x;
double y;
cin >> x >> y;
node *p = new node;
p->a = y;
p->n = x;
p->next = pn->next;
pn->next = p;
p = NULL;
delete p;
}
node *t = new node;
int count = 0;
node *p = pm->next, *q = pn->next;
while (q != NULL && p != NULL)
{
if (p->n == q->n)
{
int flag = p->a + q->a;
if (flag == 0)
{
p = p->next;
q = q->next;
}
else
{
node *temp = new node;
temp->n = p->n;
temp->a = p->a + q->a;
temp->next = t->next;
t->next = temp;
temp = NULL;
delete temp;
count++;
p = p->next;
q = q->next;
}
}
else if (p->n < q->n)
{
node *temp = new node;
temp->n = p->n;
temp->a = p->a;
temp->next = t->next;
t->next = temp;
temp = NULL;
delete temp;
count++;
p = p->next;
}
else if (p->n > q->n)
{
node *temp = new node;
temp->n = q->n;
temp->a = q->a;
temp->next = t->next;
t->next = temp;
temp = NULL;
delete temp;
count++;
q = q->next;
}
}
while (p != NULL)
{
node *temp = new node;
temp->n = p->n;
temp->a = p->a;
temp->next = t->next;
t->next = temp;
temp = NULL;
delete temp;
count++;
p = p->next;
}
while (q != NULL)
{
node *temp = new node;
temp->n = q->n;
temp->a = q->a;
temp->next = t->next;
t->next = temp;
temp = NULL;
delete temp;
count++;
q = q->next;
}
cout << count;
for (node *pstr = t->next; pstr != NULL; pstr = pstr->next)
{
cout << " ";
printf("%d %.1lf", pstr->n, pstr->a);
}
}