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

public class princess_pk {
	public static void main(String[] args) {
		new princess_pk().run();
	}

	BufferedReader br;
	StringTokenizer in;
	PrintWriter out;

	public String nextToken() throws IOException {
		while (in == null || !in.hasMoreTokens()) {
			in = new StringTokenizer(br.readLine());
		}
		return in.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	int mod(int k) {
		while (k < 0)
			k += n;
		k %= n;
		return k;
	}

	double dist(long x1, long y1, long x2, long y2) {
		return Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
	}

	long[] x, y;
	int n;

	long leftTurn(long x1, long y1, long x2, long y2, long x3, long y3) {
		long res = ((x3 - x1) * (y2 - y1) - (x2 - x1) * (y3 - y1));
		return res;
	}

	boolean checkNice(long X, long Y, int t) {
		int prev = mod(t - 1);
		int next = mod(t + 1);
		return (Long.signum(leftTurn(X, Y, x[t], y[t], x[prev], y[prev]))
				* (Long.signum(leftTurn(X, Y, x[t], y[t], x[next], y[next]))) >= 0);
	}

	boolean checkConvex(long X, long Y, int t) {
		int prev = mod(t - 1);
		int next = mod(t + 1);
		int s1 = Long.signum(leftTurn(X, Y, x[t], y[t], x[prev], y[prev]));
		int s2 = Long.signum(leftTurn(X, Y, x[t], y[t], x[next], y[next]));
		return ((s1) <= (s2));
	}

	public void solve() throws IOException {
		n = nextInt();
		int k = nextInt() - 1;
		x = new long[n * 2];
		y = new long[n * 2];
		double[] dist = new double[n];
		for (int i = 0; i < n; i++) {
			x[i] = nextInt();
			x[n + i] = x[i];
			y[i] = nextInt();
			y[n + i] = y[i];
			dist[i] = Long.MAX_VALUE / 4;
		}

		dist[k] = 0;
		int t = mod(k - 1);
		while (t != k) {
			dist[t] = Math.min(
					dist[t],
					dist[mod(t + 1)]
							+ dist(x[t], y[t], x[mod(t + 1)], y[mod(t + 1)]));
			t = mod(t - 1);
		}
		t = mod(k + 1);
		while (t != k) {
			dist[t] = Math.min(
					dist[t],
					dist[mod(t - 1)]
							+ dist(x[t], y[t], x[mod(t - 1)], y[mod(t - 1)]));
			t = mod(t + 1);
		}

		int m = nextInt();
		for (int z = 0; z < m; z++) {
			long X = nextLong();
			long Y = nextLong();
			int l = 0;
			int r = n;
			if (checkConvex(X, Y, k)) {
				out.println(dist(X, Y, x[k], y[k]));
				continue;
			}
			
			while ((checkConvex(X, Y, l) == checkConvex(X, Y, r))) {
				int c = (l + r) / 2;
				if ((checkConvex(X, Y, l) != checkConvex(X, Y, c))) {
					r = c;
					continue;
				}
				if (checkConvex(X, Y, l) != Math.signum(leftTurn(X, Y, x[c],
						y[c], x[l], y[l])) >= 0) {
					l = c;
				} else {
					r = c;
				}
			}
			
			

		}
	}

	public void run() {
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			br = new BufferedReader(new FileReader("princess.in"));
			out = new PrintWriter("princess.out");

			solve();

			out.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}
}