import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Security {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line1 = br.readLine();
		int strazny = Integer.parseInt(line1.split(" ")[0]);
		int incident = Integer.parseInt(line1.split(" ")[1]);
		int[][] index = new int[strazny][2];
		for (int i = 0; i < strazny; i++) {
			String line2 = br.readLine();
			//int x = Integer.parseInt(line2.split(" ")[0]);
			int x = Character.valueOf(line2.charAt(0)) - 48;
			//int y = Integer.parseInt(line2.split(" ")[1]);
			int y = Character.valueOf(line2.charAt(2)) - 48;
			index[i][0] = x;
			index[i][1] = y;
		}
		for (int i = 0; i < incident; i++) {
			String line2 = br.readLine();
			//int x = Integer.parseInt(line2.split(" ")[0]);
			int x = Character.valueOf(line2.charAt(0)) - 48;
			//int y = Integer.parseInt(line2.split(" ")[1]);
			int y = Character.valueOf(line2.charAt(2)) - 48;
			int vzdalenost = 0;
			double minLength = Integer.MAX_VALUE;
			int minLengthIndex = 0;
			int pythagor = 0;
			for (int j = 0; j < strazny; j++) {
				pythagor = (x - index[j][0]) * (x - index[j][0]) + (y - index[j][1]) * (y - index[j][1]);
				if (pythagor < minLength) {
					minLength = pythagor;
					minLengthIndex = j;
				}
			}
			if (Math.abs(index[minLengthIndex][0] - x) > Math.abs(index[minLengthIndex][1] - y))
				vzdalenost = Math.abs(index[minLengthIndex][0] - x);
			else
				vzdalenost = Math.abs(index[minLengthIndex][1] - y);

			System.out.println(vzdalenost);
		}
	}
}
