#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <fstream>
#include <cstdlib>
#include <cmath>

using namespace std;

int main() {
    ifstream in("DATA3.txt");
    ofstream out("OUT3.txt");
    
    for (int i = 0; i < 5; i++) {
        if (i != 0) {
            string s;
            in >> s;
            cout << s << endl;
        }
        int sa, sb;
        in >> sa >> sb;
        map<string, int> a, b;
        for (int j = 0; j < sa; j++) {
            string k; int v;
            in >> k >> v;
            a.insert(make_pair(k, v));
        }
        for (int j = 0; j < sb; j++) {
            string k; int v;
            in >> k >> v;
            b.insert(make_pair(k, v));
        }
        int common = 0;
        int sumA = 0, sumB = 0;
        for (map<string, int>::iterator p = a.begin(); p != a.end(); p++) {
            map<string, int>::iterator t = b.find(p->first);
            if (t != b.end()) {
                common++;
                sumB += abs(p->second - t->second);
            }
        }
        out << a.size() + b.size() - common * 2 << ' ' << sumB << endl;
    }
    system("pause");
    return 0;
}

