/*
 * 3.cpp
 *
 *  Created on: Mar 24, 2010
 *      Author: Justin Li
 */
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <utility>
#include <queue>
#include <stack>
#include <fstream>
using namespace std;

int main() {
	ifstream in;
	in.open("DATA3.txt"); //IS THIS RIGHT?
	ofstream out;
	out.open("OUT3.txt"); //IS THIS RIGHT?
	int a, b, j, k, nummissing, summed;
	string strs1[5];
	int ints1[5];
	string strs2[5];
	int ints2[5];
	string temps;
	for (int i=0; i<5; i++) {
		in >> a >> b;
		nummissing=0;
		summed=0;
		for (j=0;j<a;j++) {
			in >> strs1[j] >> ints1[j];
		}
		for (j=0;j<b;j++) {
			in >> strs2[j] >> ints2[j];
		}
		in >> temps;
		if (temps!="---") ; //crap
		bool good;
		for (j=0;j<a;j++) {
			good = false;
			for (k=0;k<b;k++) {
				if (strs1[j] == strs2[k]) {
					summed+=max(ints1[j]-ints2[k], ints2[k]-ints1[j]);
					good = true;
					break;
				}
			}
			if (!good) {
				//cout << j << " " << strs1[j] << " ";
				nummissing++;
			}
		}
		for (j=0;j<b;j++) {
			good = false;
			for (k=0;k<a;k++) {
				if (strs2[j] == strs1[k]) {
					good = true;
					break;
				}
			}
			if (!good) {
				//cout << j << " " << strs2[j] << " ";
				nummissing++;
			}
		}

		out << nummissing << " " << summed << endl;
	}
	in.close();
	out.close();
	return 0;
}

