import java.io.*;
import java.util.*;
public class C
{
    public static void main (String[] args) throws IOException
    {
	BufferedReader in = new BufferedReader (new FileReader ("DATA3.txt"));
	PrintWriter out = new PrintWriter (new FileWriter ("OUT3.txt"));
	for (int a = 0 ; a < 5 ; a++)
	{
	    int b = Integer.parseInt (in.readLine ());
	    int c = Integer.parseInt (in.readLine ());
	    int linesDiff = 0;
	    //int linesDiff = Math.abs (b - c);
	    int numDiff = 0;
	    String file1[] = new String [b];
	    String file1A[] = new String [b];
	    String file2[] = new String [c];
	    String file2A[] = new String [c];

	    for (int d = 0 ; d < b ; d++)
	    {
		String s[] = in.readLine ().split (" ");
		file1 [d] = s [0];
		file1A [d] = s [1];
	    }
	    for (int d = 0 ; d < c ; d++)
	    {
		String s[] = in.readLine ().split (" ");
		file2 [d] = s [0];
		file2A [d] = s [1];
	    }
	    for (int e = 0 ; e < b ; e++)
	    {
		int index = Arrays.binarySearch (file2, file1 [e]);
		if (index < 0)
		{
		    linesDiff++;
		}
		else
		{
		    numDiff += Math.abs (Integer.parseInt (file1A [e]) - Integer.parseInt (file2A [index]));
		    file2 [index] = "";
		}
	    }
	    for (int e = 0 ; e < c ; e++)
	    {
		if (!file2 [e].equals (""))
		{
		    linesDiff++;
		}
	    }
	    out.println (linesDiff + " " + numDiff);
	    in.readLine ();

	}


	out.close ();
	in.close ();
    }
}

