import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.*;

public class princess_ak_slow {

	final static double EPS = 1e-9;
	
	static class Point {
		double x, y;

		public Point(double x, double y) {
			this.x = x;
			this.y = y;
		}
		
		double distTo(Point p) {
			return Math.sqrt((p.x - x) * (p.x - x) + (p.y - y) * (p.y - y));
		}
		
		double vMul(Point p) {
			return x * p.y - y * p.x;
		}
		
		@Override
		public String toString() {
			return "(" + x + ", " + y + ")";
		}
	}

	static class Polygon {
		Point[] p;
		int n;
		double perimeter;
		double[] sumLength;
		int[] tangents;
		
		public Polygon(Point[] p) {
			this.p = p;
			n = p.length;
			sumLength = new double[n];
			perimeter = p[0].distTo(p[n - 1]);
			for (int i = 1; i < n; i++) {
				sumLength[i] = sumLength[i - 1] + p[i].distTo(p[i - 1]);
			}
			perimeter += sumLength[n - 1];
			tangents = new int[2];
		}
		
		int norm(int i) {
			return ((i % n) + n) % n;
		}
		
		double calcDistByEdge(int v1, int v2) {
			v1 = norm(v1);
			v2 = norm(v2);
			double d = Math.abs(sumLength[v1] - sumLength[v2]);
			return Math.min(d, perimeter - d);
		}
		
		private Point get(int i) {
			return p[norm(i)];
		}
		
		private int orientation(Point a, Point b, Point c) { // sign of /_ABC
			double vect = (b.x - a.x) * (c.y - b.y) - (b.y - a.y) * (c.x - b.x); // BA x BC
			if (Math.abs(vect) < EPS)
				return 0;
			return vect < 0 ? -1 : 1;
		}
		
		private void calcTangents(Point q) {
			tangents[0] = tangents[1] = -1;
			for (int i = 0; i < n; i++)  {
				int prev = (i + n - 1) % n;
				int next = (i + 1) % n;
				int or1 = orientation(p[i], q, p[prev]);
				int or2 = orientation(p[i], q, p[next]);
				if (or1 <= 0 && or2 <= 0) {
					if (tangents[1] == -1) {
						tangents[1] = i;
					} else {
						double dist1 = q.distTo(get(tangents[1]));
						double dist2 = q.distTo(p[i]);
						if (dist2 < dist1) {
							tangents[1] = i;
						}
					}
				}
				if (or1 >= 0 && or2 >= 0) {
					if (tangents[0] == -1) {
						tangents[0] = i;
					} else {
						double dist1 = q.distTo(get(tangents[0]));
						double dist2 = q.distTo(p[i]);
						if (dist2 < dist1) {
							tangents[0] = i;
						}
					}
				}
			}
		}
		
		double get(Point q, int v) {
			calcTangents(q);
			if (tangents[1] < tangents[0])
				tangents[1] += n;
			if (v < tangents[0])
				v += n;
			if (tangents[0] <= v && v <= tangents[1]) {
				return q.distTo(get(v));
			}
			double ans1 = q.distTo(get(tangents[0])) + calcDistByEdge(v, tangents[0]);
			double ans2 = q.distTo(get(tangents[1])) + calcDistByEdge(v, tangents[1]);
			return Math.min(ans1, ans2);
		}
	
	}

	void solve() {
		int n = in.nextInt();
		int v = in.nextInt() - 1;
		Point[] pp = new Point[n];
		for (int i = 0; i < n; i++) {
			pp[i] = new Point(in.nextInt(), in.nextInt());
		}
		Polygon p = new Polygon(pp);
		int m = in.nextInt();
		for (int i = 0; i < m; i++) {
			Point q = new Point(in.nextInt(), in.nextInt());
			out.println(p.get(q, v));
		}
		
	}

	Scanner in;
	PrintWriter out;

	void run() throws FileNotFoundException {
		in = new Scanner(new File("princess.in"));
		out = new PrintWriter("princess.out");
		solve();
		out.close();
	}

	public static void main(String[] args) throws FileNotFoundException {
		new princess_ak_slow().run();
	}
}
