The Traveling Orienteerer

No attempts yetTime limit1sMemory limit256 MB

Problem

Lasse is putting together the courses for an orienteering meet. A course is a list of control points visited in the given order, and Lasse needs one whose length is just right. He has no time to run every candidate himself, so Ola walks the forest with a GPS and records the coordinates of every control point. The lengths can now be computed from the coordinates alone.

The length of a course is the sum of the Euclidean distances between consecutive control points, in the order the course lists them. The distance between (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) is (x1x2)2+(y1y2)2\sqrt{(x_1 - x_2)^2 + (y_1 - y_2)^2}.

Given the coordinates of the control points and the list of courses, compute the total length of each course.

Input

The first line contains the number of control points nn (1n10001 \le n \le 1000). Each of the next nn lines contains the coordinates xix_i and yiy_i of one control point as floating-point numbers (0.0xi,yi10000.00.0 \le x_i, y_i \le 10000.0). Control points are numbered 00 to n1n - 1 in the order they are given.

The next line contains the number of courses mm (1m1001 \le m \le 100). Each course takes two lines. The first line holds the number of control points pp on the course (2p172 \le p \le 17), counting the start and the finish. The second line holds pp control point numbers in the order they are visited (0i<n0 \le i < n). The same control point may appear several times on one course.

Output

For each course print its total length on its own line, rounded to an integer with no decimals. A fractional part of exactly 0.50.5 rounds up. Process the courses in the order they are given.