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) and (x2,y2) is (x1−x2)2+(y1−y2)2.
Given the coordinates of the control points and the list of courses, compute the total length of each course.
The first line contains the number of control points n (1≤n≤1000). Each of the next n lines contains the coordinates xi and yi of one control point as floating-point numbers (0.0≤xi,yi≤10000.0). Control points are numbered 0 to n−1 in the order they are given.
The next line contains the number of courses m (1≤m≤100). Each course takes two lines. The first line holds the number of control points p on the course (2≤p≤17), counting the start and the finish. The second line holds p control point numbers in the order they are visited (0≤i<n). The same control point may appear several times on one course.
For each course print its total length on its own line, rounded to an integer with no decimals. A fractional part of exactly 0.5 rounds up. Process the courses in the order they are given.