// Arup Guha
// 7/22/2013
// Solution to SI@UCF Homework Problem Paths (taken from 2004 UCF HS contest)

import java.util.*;

public class paths {
	
	final public static int MAX = 10;
	final public static int AVOID = -1;
	
	public static void main(String[] args) {
		
		Scanner stdin = new Scanner(System.in);
		int numCases = stdin.nextInt();
		
		// Go through each case.
		for (int loop=1; loop<=numCases; loop++) {
			
			int[][] grid = new int[MAX][MAX];

			// Fill in illegal squares.
			int n = stdin.nextInt();
			for (int i=0; i<n; i++) {
				int x = stdin.nextInt();
				int y = stdin.nextInt();
				grid[x][y] = AVOID;
			}
			
			// Print out case header.
			System.out.println("Data Set "+loop+":");
			System.out.println();
			
			// Answer each query.
			int trips = stdin.nextInt();
			for (int i=1; i<=trips; i++) {
				
				// Get starting and ending locations.
				int sx = stdin.nextInt();
				int sy = stdin.nextInt();
				int ex = stdin.nextInt();
				int ey = stdin.nextInt();
				
				// Solve and output.
				int ans = solve(grid, sx, sy, ex, ey);
				if (ans != 1)
					System.out.println("  Test Case "+i+": Nick can take "+ans+" perfect paths.");
				else
					System.out.println("  Test Case "+i+": Nick can take 1 perfect path.");
			}
			System.out.println();			
		}
		
	}
	
	// Solves a single query.
	public static int solve(int[][] grid, int sx, int sy, int ex, int ey) {
		
		// Store all subanswers in this array.
		int[][] dp = new int[MAX][MAX];
		dp[sx][sy] = 1;
		int dx = 1, dy = 1;
		
		// Only set dx and dy if our travel grid has width > 1.
		if (ex != sx)
			dx = (ex - sx)/((int)Math.abs(ex - sx));
		if (ey != sy)
			dy = (ey - sy)/((int)Math.abs(ey - sy));
		
		// Go through array in order, building number of paths.
		for (int x=sx; x != ex+dx; x+=dx) {
			for (int y=sy; y != ey+dy; y+=dy) {
				
				//System.out.println(x+" "+y);
				
				// We filled this in already.
				if (x == sx && y == sy) continue;
				
				// We can't go here.
				if (grid[x][y] == -1) continue;
				
				// Add in contributions from both directions, if in bounds.
				if (x != sx)
					dp[x][y] += dp[x-dx][y];
				if (y != sy)
					dp[x][y] += dp[x][y-dy];
			}
		}
		
		// This is our answer.
		return dp[ex][ey];
	}
}