#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <ctime>

#define forr(a,b,c) for(int (a) = (b); (a) < (c); ++ (a))
#define fore(a,b,c) for(int (a) = (b); (a) <= (c); ++ (a))

#define pii pair<int,int>
#define int3 pair<pair<int,int>, int>
#define vi vector<int>
#define ull long long
#define vs vector<string>

//#define DEBUG

using namespace std;


int main(){
	
	#ifndef DEBUG
		freopen("DATA3.txt", "r", stdin);
		freopen("OUT3.txt", "w", stdout);
	#endif
	
	forr(_r,0,5){
		int n, m;
		vector<pair<string,int> > k1, k2;
		
		string garb;
		
		cin >> n >> m;
		
		for(int i=0; i<n; ++i){
			string ts; int ti;
			cin >> ts >> ti;
			k1.push_back(make_pair(ts,ti));
		}
		
		for(int i=0; i<m; ++i){
			string ts; int ti;
			cin >> ts >> ti;
			k2.push_back(make_pair(ts,ti));
		}
		
		bool m1[100], m2[100];
		int nmis=0, sdif=0;
		
		memset(m1,0,sizeof(m1));
		memset(m2,0,sizeof(m2));
		
		for(int i=0; i<n; ++i){
			if(m1[i]) continue;
			
			for(int j=0; j<m; ++j){
				if(m2[j]) continue;
				
				if(k1[i].first == k2[j].first){
					m1[i] = m2[j] = 1;
					sdif += abs(k1[i].second - k2[j].second);
					break;
				}
			}
		}
		
		for(int i=0; i<n; ++i) nmis += !m1[i];
		for(int i=0; i<m; ++i) nmis += !m2[i];
		
		cout << nmis << ' ' << sdif << '\n';
		
		cin >> garb; //---
	}
	
	#ifdef DEBUG
		system("pause");
	#endif
	
	return 0;
}

