// Arup Guha
// 3/9/2021
// Solution to 2021 UCF HS Contest Problem: Night Watch

import java.util.*;

public class night {

	public static void main(String[] args) {
	
		// Get the # of cases.
		Scanner stdin = new Scanner(System.in);
		int nC = stdin.nextInt();
		
		// Process all cases.
		for (int loop=0; loop<nC; loop++) {
		
			// Get my position and the amount you are allowed to lose.
			int miss = stdin.nextInt();
			int myX = stdin.nextInt();
			int myY = stdin.nextInt();
			
			int n = stdin.nextInt();
			int[] x = new int[n];
			int[] y = new int[n];
			
			// Store coordinates relative to your view.
			for (int i=0; i<n; i++) {
				x[i] = stdin.nextInt()-myX;
				y[i] = stdin.nextInt()-myY;
			}
			
			// Just get all the angles from me to the points via atan2.
			double[] angles = new double[n];
			for (int i=0; i<n; i++)
				angles[i] = Math.atan2(1.0*y[i], 1.0*x[i]);
			
			// Sort for our sweep.
			Arrays.sort(angles);
			double[] angles2 = new double[2*n];
			
			// Double the list so we can just sweep on a line and not a circle...
			for (int i=0; i<n; i++) angles2[i] = angles[i];
			for (int i=n; i<2*n; i++) angles2[i] = angles[i%n] + 2*Math.PI;
			
			// These are index pointers.
			int low = 0, high = 0;
			int res = 0;
			
			// Go till our high pointer goes off the end.
			while (high < 2*n) {
			
				// This is a valid range, count it and update high.
				if (angles2[high] - angles2[low] < Math.PI/2+1e-9) {
					res = Math.max(res, high-low+1);
					high++;
				}
				
				// Since the range isn't valid we are safe to increment low.
				else
					low++;
			}
		
			// Ta da!
			System.out.println(Math.max(0,n-res-miss));
		}
	}
}