import java.util.*;
import java.io.*;

/**
 * Author: Sebastian Kanthak
 * Complexity: O(n\log n)
 */
public class castlewalls {
    static class Line implements Comparable {
	int y1,y2;

	Line(int y1,int y2) {
	    this.y1 = y1;
	    this.y2 = y2;
	}

	public int compareTo(Object o) {
	    Line that = (Line)o;
	    return this.y1-that.y1;
	}
    }

    public static void main(String[] args) throws Exception {
	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	int scenarios = Integer.parseInt(in.readLine());
	for (int scen=1; scen <= scenarios; ++scen) {
	    System.out.println("Scenario #"+scen+":");
	    StringTokenizer t = new StringTokenizer(in.readLine());
	    int n = Integer.parseInt(t.nextToken());
		assert 1 <= n && n <= 30000;
	    int m = Integer.parseInt(t.nextToken());
		assert 1 <= m && m <= 30000;
	    Line[] blue = new Line[n];
	    Line[] red = new Line[m];
	    for (int i=0; i < n; ++i) {
			blue[i] = parseLine(in.readLine());
			assert 1 <= blue[i].y1 && blue[i].y1 <= n+m;
			assert 1 <= blue[i].y2 && blue[i].y2 <= n+m;
	    }
	    for (int i=0; i < m; ++i) {
			red[i] = parseLine(in.readLine());
			assert 1 <= red[i].y1 && red[i].y1 <= n+m;
			assert 1 <= red[i].y2 && red[i].y2 <= n+m;
	    }
	    //System.out.println("n^2: "+count2(blue,red));
	    // sort lines vertically
	    Arrays.sort(blue);
	    Arrays.sort(red);

		assert separated(blue) && separated(red);
		assert checkPeasants(red,blue);
		
	    // go through blue lines, maintining the
	    // interval of red lines intersectd by the
	    // current blue line
	    int l=0;
	    int u=0;
	    long count=0;
	    for (int i=0; i < n; ++i) {
		while (l < m && red[l].y1 < blue[i].y1 &&
		       red[l].y2 < blue[i].y2) {
		    ++l;
		}
		u = Math.max(u,l);
		while (u < m && 
		       (red[u].y1 <= blue[i].y1 ||
			red[u].y2 <= blue[i].y2)) {
		    ++u;
		}
		count += (u-l);
	    }
	    System.out.println(count);
	    System.out.println();
	}
    }

	static boolean separated(Line[] lines) {
		for (int i=1; i < lines.length; ++i) {
			if (lines[i-1].y1 >= lines[i].y1 ||
				lines[i-1].y2 >= lines[i].y2) return false;
		}
		return true;
	}

	static boolean checkPeasants(Line[] red,Line[] blue) {
		boolean[] used = new boolean[red.length+blue.length];
		for (int i=0; i < red.length; ++i) {
			if (used[red[i].y1-1]) return false;
			used[red[i].y1-1] = true;
		}
		for (int i=0; i < blue.length; ++i) {
			if (used[blue[i].y1-1]) return false;
			used[blue[i].y1-1] = true;
		}
		return true;
	}
		
    static long count2(Line[] blue,Line[] red) {
		long count=0;
		for (int i=0; i < blue.length; ++i) {
			for (int j=0; j < red.length; ++j) {
				if ((blue[i].y1 < red[j].y1 &&
					blue[i].y2 >= red[j].y2) ||
					(blue[i].y1 > red[j].y1 &&
					blue[i].y2 <= red[j].y2)) {
						++count;
				}
			}
		}
		return count;
    }

    static Line parseLine(String in) {
		StringTokenizer t = new StringTokenizer(in);
		return new Line(Integer.parseInt(t.nextToken()),
				Integer.parseInt(t.nextToken()));
    }
}
