import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class princess_ak {

	final static int MAXK = 100000000;
	final static int MAXN = 100000;
	final static int MAXM = 100000;
	
	static enum Orientation {
		LEFT, RIGHT, ON
	}

	static enum Convexivity {
		CONVEX, UNCONVEX, LEFT_TANGENT, RIGHT_TANGENT
	}

	static class Point {
		long x, y;

		public Point(long x, long y) {
			if (x < -MAXK || x > MAXK || y < -MAXK || y > MAXK)
				throw new AssertionError();
			this.x = x;
			this.y = y;
		}

		long dist2To(Point p) {
			return (p.x - x) * (p.x - x) + (p.y - y) * (p.y - y);
		}

		@Override
		public String toString() {
			return "(" + x + ", " + y + ")";
		}

		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			Point other = (Point) obj;
			if (x != other.x)
				return false;
			if (y != other.y)
				return false;
			return true;
		}
		
	}

	static class Polygon {
		Point[] p;
		int n;
		int leftTangent, rightTangent, convex, unconvex;
		double[] sumLength;
		double perimeter;

		class RingSegment {
			int left, right;

			public RingSegment(int left, int right) {
				if (left > right)
					right += n;
				this.left = left;
				this.right = right;
			}

			public int mid() {
				return (left + right) / 2;
			}

			public int length() {
				return right - left;
			}
		}

		public Polygon(Point[] p) {
			this.p = p;
			n = p.length;
			sumLength = new double[n + 1];
			perimeter = Math.sqrt(p[0].dist2To(p[n - 1]));
			for (int i = 1; i < n; i++) {
				sumLength[i] = sumLength[i - 1]
						+ Math.sqrt(p[i].dist2To(p[i - 1]));
			}
			perimeter += sumLength[n - 1];
		}

		double calcDistByEdge(int v1, int v2) {
			v1 = (v1 % n + n) % n;
			v2 = (v2 % n + n) % n;
			double d = Math.abs(sumLength[v1] - sumLength[v2]);
			return Math.min(d, perimeter - d);
		}

		Point get(int i) {
			return p[(i % n + n) % n];
		}

		void update(Convexivity c, int i) {
			if (c == Convexivity.CONVEX) {
				if (convex == -1)
					convex = i;
			} else if (c == Convexivity.UNCONVEX) {
				if (unconvex == -1)
					unconvex = i;
			} else if (c == Convexivity.LEFT_TANGENT) {
				if (leftTangent == -1) {
					leftTangent = i;
					if (ready())
						return;
					getConvexivity(q, i + 1);
					getConvexivity(q, i - 1);
				}
			} else {
				if (rightTangent == -1) {
					rightTangent = i;
					if (ready())
						return;
					getConvexivity(q, i + 1);
					getConvexivity(q, i - 1);
				}
			}
		}

		Point q;
		
		Convexivity getConvexivity(Point q, int i) {
			Convexivity result;
			if (get(i).equals(q)) {
				leftTangent = rightTangent = i;
				update(Convexivity.LEFT_TANGENT, i);
				update(Convexivity.RIGHT_TANGENT, i);
				convex = unconvex = 0;
				return Convexivity.LEFT_TANGENT;
			}
			Orientation next = turn(q, get(i), get(i + 1));
			Orientation prev = turn(q, get(i), get(i - 1));
			if (prev != Orientation.LEFT && next == Orientation.RIGHT) {
				result = Convexivity.LEFT_TANGENT;
			} else if (next != Orientation.RIGHT && prev == Orientation.LEFT) {
				result = Convexivity.RIGHT_TANGENT;
			} else if (prev == Orientation.RIGHT || next == Orientation.LEFT) {
				result = Convexivity.UNCONVEX;
			} else if (next == Orientation.RIGHT || prev == Orientation.LEFT) {
				result = Convexivity.CONVEX;
			} else {
				throw new AssertionError("Can't identify vertex' tyep");
			}
			update(result, i);
			return result;
		}

		boolean ready() {
			return (convex != -1 && unconvex != -1) || (leftTangent != -1 && rightTangent != -1);
		}

		void calcRightTangent(Point q) {
			RingSegment seg = new RingSegment(convex, unconvex);
			while (seg.length() > 1) {
				int mid = seg.mid();
				Convexivity c = getConvexivity(q, mid);
				if (c == Convexivity.CONVEX) {
					seg.left = mid;
				} else {
					seg.right = mid;
				}
			}
			if (rightTangent == -1)
				throw new AssertionError("right :'(");
		}

		void calcLeftTangent(Point q) {
			RingSegment seg = new RingSegment(unconvex, convex);
			while (seg.length() > 1) {
				int mid = seg.mid();
				Convexivity c = getConvexivity(q, mid);
				if (c == Convexivity.UNCONVEX) {
					seg.left = mid;
				} else {
					seg.right = mid;
				}
			}
			if (leftTangent == -1)
				throw new AssertionError("left :'(");
		}

		void calcTangents(Point q) {
			leftTangent = rightTangent = convex = unconvex = -1;
			if (n < 4)
				for (int i = 0; i < n; i++)
					getConvexivity(q, i);
			Convexivity c1 = getConvexivity(q, 0);
			Convexivity c2 = getConvexivity(q, n / 2);

			int left, right;

			if (turn(q, get(0), get(n / 2)) == Orientation.LEFT) {
				right = 0;
				left = n / 2;
			} else {
				right = n / 2;
				left = 0;
			}

			RingSegment seg;
			if (convex != -1) {
				seg = new RingSegment(right, left);
			} else {
				seg = new RingSegment(left, right);
			}

			while (!ready()) {
				int mid = seg.mid();
				Convexivity c = getConvexivity(q, mid);
				if (c == Convexivity.CONVEX) {
					if (turn(q, get(seg.left), get(mid)) == Orientation.RIGHT) {
						seg.left = mid;
					} else {
						seg.right = mid;
					}
				} else {
					if (turn(q, get(seg.right), get(mid)) == Orientation.RIGHT) {
						seg.right = mid;
					} else {
						seg.left = mid;
					}
				}
			}

			calcLeftTangent(q);
			calcRightTangent(q);
		}

		double get(Point q, int v) {
			this.q = q;
			calcTangents(q);
			RingSegment seg = new RingSegment(leftTangent, rightTangent);
			while (v < seg.left)
				v += n;
			if (seg.left <= v && v <= seg.right) {
				return Math.sqrt(get(v).dist2To(q));
			}
			double ans1 = Math.sqrt(get(rightTangent).dist2To(q)) + calcDistByEdge(v, rightTangent);
			double ans2 = Math.sqrt(get(leftTangent).dist2To(q)) + calcDistByEdge(v, leftTangent);
			return Math.min(ans1, ans2);
		}
	}

	static Orientation turn(Point a, Point b, Point c) { // sign of /_bac
		long res = (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
		if (res == 0)
			return Orientation.ON;
		else if (res > 0)
			return Orientation.LEFT;
		else
			return Orientation.RIGHT;
	}

	void checkIfConvex(Polygon p) {
		for (int i = 0; i < p.p.length; i++) {
			if (turn(p.get(i), p.get(i + 1), p.get(i + 2)) != Orientation.LEFT) {
				throw new AssertionError();
			}
		}
	}
	
	void solve() throws IOException {

		int n = nextInt();
		if (n < 1 || n > MAXN)
			throw new AssertionError();
		
		int v = nextInt() - 1;
		Point[] p = new Point[n];
		for (int i = 0; i < n; i++) {
			p[i] = new Point(nextInt(), nextInt());
		}
		Polygon poly = new Polygon(p);
		int m = nextInt();
		if (m < 1 || m > MAXM)
			throw new AssertionError();
		for (int i = 0; i < m; i++) {
			//System.err.println(i);
			Point q = new Point(nextInt(), nextInt());
			out.println(poly.get(q, v));
		}
	}

	static BufferedReader br;
	static PrintWriter out;
	static StringTokenizer st = null;

	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new FileReader(new File("princess.in")));
		out = new PrintWriter("princess.out");
		new princess_ak().solve();
		out.close();
	}

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

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