#include <iostream>
using namespace std;
int amount = 0;
void store(int cases, double a[])
{
    int index = 0;
    double value = 0;
    for (int i = 0; i < cases; i++)
    {

        cin >> index;
        cin >> value;
        a[index] += value;
    }
}

int main()
{
    double a[2000] = {};
    int cases;
    cin >> cases;
    store(cases, a);
    cin >> cases;
    store(cases, a);
    for (int i = 0; i < 1999; i++)
        if (a[i] != 0)
            amount++;
    cout << amount;
    for (int i = 1999; i >= 0; i--)
    {
        if (a[i] != 0.0 && a[i] != 0)
            printf(" %d %.1f", i, a[i]);
    }
    return 0;
}