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

public class princess_ak_wa {

	final static double EPS = 1e-9;
	
	void checkIfConvex(Polygon p) {
		for (int i = 0; i < p.n; i++) {
			int o = Polygon.orientation(p.get(i + 1), p.get(i), p.get(i + 2));
			if (o != -1)
				throw new AssertionError();
		}
	}
	
	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 leftTangent, rightTangent;
		
		private static class Nearer implements Comparator<Point> {
			Point p;
			
			public Nearer(Point p) {
				this.p = p;
			}
			
			@Override
			public int compare(Point o1, Point o2) {
				double d1 = p.distTo(o1);
				double d2 = p.distTo(o2);
				if (Math.abs(d1 - d2) < EPS)
					return 0;
				return d1 < d2 ? -1 : 1;
			}
		}
		
		private static class Further implements Comparator<Point> {
			Point p;
			
			public Further(Point p) {
				this.p = p;
			}
			
			@Override
			public int compare(Point o1, Point o2) {
				double d1 = p.distTo(o1);
				double d2 = p.distTo(o2);
				if (Math.abs(d1 - d2) < EPS)
					return 0;
				return d1 > d2 ? -1 : 1;
			}
		}
		
		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];
		}
		
		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 getOptimal(Comparator<Point> f) {
			int L = 0;
			int R = 2 * n;
			while (R - L > 2) {
				int c1 = (2 * L + R) / 3;
				int c2 = (L + 2 * R) / 3;
				if (f.compare(get(c1), get(c2)) < 0) {
					R = c2;
				} else {
					L = c1;
				}
			}
			int opt = L;
			if (f.compare(get(opt), get(L + 1)) >= 0) {
				opt = L + 1;
			}
			
			int res1 = f.compare(get(opt), get(opt - 1));
			int res2 = f.compare(get(opt), get(opt + 1));
//			System.err.println(res1 + " " + res2 + " " + opt + " " + n);
			
			return opt;	
		}
		
		private int getNearest(Point p) {
			return getOptimal(new Nearer(p));
		}
		
		private int getFurthest(Point p) {
			return getOptimal(new Further(p));
		}
		
		static 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) {
			int furthest = getFurthest(q);
			int nearest = getNearest(q);
//			System.err.println("Big: " + q.distTo(get(furthest)));
//			System.err.println("Small: " + q.distTo(get(nearest)));
			double big = q.distTo(get(furthest));
			double small = q.distTo(get(nearest));
			for (int i = 0; i < n; i++) {
				Point pp = p[i];
				System.err.println(i + " " + pp.distTo(q));
//				if (pp.distTo(q) > big) 
//					throw new AssertionError("Big :( :: " + big + " < " + pp.distTo(q) + " at " + i + " // " + furthest);
//				if (pp.distTo(q) < small)
//					throw new AssertionError("Small :( :: " + small + " > " + pp.distTo(q) + " at " + i + " // " + nearest);
			}
			if (furthest < nearest)
				furthest += n;
			int L = nearest - 1;
			int R = furthest + 1;
			while (R - L > 1) {
				int c = (L + R) / 2;
				if (orientation(q, get(c), get(c + 1)) < 0)
					L = c;
				else
					R = c;
			}
			leftTangent = R;
			L = furthest - 1;
			R = nearest + n + 1;
			while (R - L > 1) {
				int c = (L + R) / 2;
				if (orientation(q, get(c), get(c + 1)) > 0)
					L = c;
				else
					R = c;
			}
			rightTangent = R;
		}
		
		double get(Point q, int v) {
			calcTangents(q);
			leftTangent = norm(leftTangent);
			rightTangent = norm(rightTangent);
			// если v \in [right..left], то можно идти напрямую
			if (leftTangent < rightTangent)
				leftTangent += n;
			if (v < rightTangent)
				v += n;
			if (rightTangent <= v && v <= leftTangent)
				return q.distTo(get(v));
			double ans1 = get(leftTangent).distTo(q) + calcDistByEdge(v, leftTangent);
			double ans2 = get(rightTangent).distTo(q) + calcDistByEdge(v, rightTangent);
			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);
		checkIfConvex(p);
		int m = in.nextInt();
		for (int i = 0; i < m; i++) {
//			System.err.println(i + 1);
			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_wa().run();
	}
}
