Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.

You are given a convex polygon with N sides. You have to answer Q queries. The i^{th} query is described by two integers v_{i}, t_{i}. In this query, all sides of the polygon start moving parallel to their respective perpendicular vector away from the centroid with a constant velocity of v_{i} \frac{units}{sec}. Output the final area covered by N sides of the polygon after time t_{i} seconds. 

For each query,  consider the initial coordinates of vertices of the given polygon.

Note: 
Since the input-output is large, prefer using fast input-output methods.
The problem requires high precision, so prefer using data types with a precision equivalent to long double in C++.

------ Input Format ------ 

- The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- Each testcase contains N + Q + 1 lines of input.
- The first line of each test case contains two space-separated integers N, Q.
- N  lines follow. For each valid i, the i^{th} of these lines contains two space-separated integers x_{i}, y_{i}, coordinates of the i^{th} vertex of the polygon.
- Next Q lines follow. For each valid i, the i^{th} of these lines contains two space-separated integers  v_{i}, t_{i}, description of the i^{th} query.

------ Output Format ------ 

For each query, output in a single line the final area covered by N sides of the polygon. 

Your answer will be considered correct if its relative or absolute error does not exceed 10^{-2}.

------ Constraints ------ 

$1 ≤ T ≤ 250$
$3 ≤ N ≤ 10^{4}$
$1 ≤ Q ≤ 10^{4}$
$0 ≤ x_{i}, y_{i} ≤ 2 \cdot 10^{6}$
$1 ≤ v_{i}, t_{i} ≤ 10^{5}$
$1 ≤ v_{i} \cdot t_{i} ≤ 10^{5}$
- The sum $N$ over all testcases does not exceed $5 \cdot 10^{5}$.
- The sum $Q$ over all testcases does not exceed $5 \cdot 10^{5}$.
- The vertices of polygon are given in counter-clockwise order.
- The internal angles of the given polygon are greater than $1^{\circ}$. 

------ subtasks ------ 

Subtask #1 (100 points): original constraints

----- Sample Input 1 ------ 
2
4 1
1 1
2 1
2 2
1 2
1 1
3 2
1 1
2 1
1 2
1 1
2 3
----- Sample Output 1 ------ 
9.0000000
9.7426406
230.8086578
----- explanation 1 ------ 
Below are the images for the respective test cases. Inner polygons are the ones at the start and the rays represent the distance traveled by the sides at the given speed in a given time. Outer polygons denote the final ones after the movements of the sides.

Test case $1$:

Test case $2$: $1^{st}$ query

Source: codechef | Difficulty: VERY_HARD
Tags: Geometry


Solutions:
import sys
from math import atan2, pi, hypot, tan
input = sys.stdin.readline

def polygon_area(x, y, n):
	area = 0
	j = n - 1
	for i in range(n):
		area += (x[j] + x[i]) * (y[j] - y[i])
		j = i
	return abs(area / 2)

def get_angle(i, x, y, n):
	p1 = i
	p2 = (i + 1) % n
	p3 = (i - 1) % n
	angle = atan2(y[p3] - y[p1], x[p3] - x[p1]) - atan2(y[p2] - y[p1], x[p2] - x[p1])
	if angle < 0:
		angle += 2 * pi
	return angle

def solve():
	(n, q) = map(int, input().split())
	x = [0] * n
	y = [0] * n
	for i in range(n):
		(a, b) = map(int, input().split())
		x[i] = a
		y[i] = b
	original_area = polygon_area(x, y, n)
	sum_of_sides = 0
	for i in range(n):
		a = i
		b = (i + 1) % n
		sum_of_sides += hypot(x[a] - x[b], y[a] - y[b])
	tans = [tan(get_angle(i, x, y, n) / 2) for i in range(n)]
	inverses = sum((1 / x for x in tans))
	for _ in range(q):
		(v, t) = map(int, input().split())
		d = v * t
		new_area = original_area + d * sum_of_sides + d * d * inverses
		print(f'{new_area:.08f}')

def main():
	for t in range(int(input())):
		solve()
main()


from math import sqrt
for _ in range(int(input())):
	(n, q) = map(int, input().split())
	coordinates = []
	for i in range(n):
		(x, y) = map(int, input().split())
		coordinates.append([x, y])
	original_area = 0.0
	area_corner_trianges = 0.0
	perimeter = 0.0
	for i in range(n):
		(x0, y0) = (coordinates[i - 1][0], coordinates[i - 1][1])
		(x1, y1) = (coordinates[i][0], coordinates[i][1])
		(x2, y2) = (coordinates[(i + 1) % n][0], coordinates[(i + 1) % n][1])
		perimeter += sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
		original_area += x1 * y2 - y1 * x2
		i1 = x0 - x1
		j1 = y0 - y1
		i2 = x2 - x1
		j2 = y2 - y1
		cosVal = (i1 * i2 + j1 * j2) / (sqrt(i1 ** 2 + j1 ** 2) * sqrt(i2 ** 2 + j2 ** 2))
		area_corner_trianges += sqrt((1 + cosVal) / (1 - cosVal))
	original_area = 0.5 * abs(original_area)
	for i in range(q):
		(v, t) = map(int, input().split())
		d = v * t
		ans = original_area + d * perimeter + d ** 2 * area_corner_trianges
		print('{0:.7f}'.format(ans))


from math import sqrt, acos, pi, tan

def distance(p1, p2):
	return sqrt((p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1]))

def angleWithPoints(p0, p1, p2):
	vec1 = [p0[0] - p1[0], p0[1] - p1[1]]
	vec2 = [p0[0] - p2[0], p0[1] - p2[1]]
	return acos((vec1[0] * vec2[0] + vec1[1] * vec2[1]) / (distance(p0, p1) * distance(p0, p2)))
for _ in range(int(input())):
	(size, q) = map(int, input().split())
	points = []
	totalArea = 0.0
	totalPerimeter = 0.0
	delta = 0.0
	for i in range(size):
		(x, y) = map(float, input().split())
		points.append([x * 1.0, y * 1.0])
	for i in range(size):
		prevP = points[(i - 1 + size) % size]
		currP = points[i]
		nextP = points[(i + 1) % size]
		totalArea += currP[0] * nextP[1] - nextP[0] * currP[1]
		totalPerimeter += distance(currP, nextP)
		theta = pi - angleWithPoints(currP, prevP, nextP)
		delta += tan(theta / 2.0)
	totalArea *= 0.5
	for i in range(q):
		(v, ti) = map(float, input().split())
		d = v * 1.0 * (ti * 1.0)
		ans = totalArea + totalPerimeter * d + delta * d * d
		print('%.10f' % ans)


def distance(x1, y1, x2, y2):
	ans = (x1 - x2) ** 2 + (y1 - y2) ** 2
	ans = ans ** 0.5
	return ans

def cosine(x1, y1, x2, y2, x3, y3):
	a = distance(x1, y1, x2, y2)
	b = distance(x3, y3, x2, y2)
	c = distance(x1, y1, x3, y3)
	ans = a * a + b * b - c * c
	ans /= 2 * a * b
	return ans

def cothalf(x1, y1, x2, y2, x3, y3):
	cos = (cosine(x1, y1, x2, y2, x3, y3) + 1) / 2
	sin = 1 - cos
	ans = cos / sin
	ans = ans ** 0.5
	return ans

def cotsum(x, y, n):
	ans = 0
	for i in range(n - 2):
		ans += cothalf(x[i], y[i], x[i + 1], y[i + 1], x[i + 2], y[i + 2])
	ans += cothalf(x[n - 2], y[n - 2], x[n - 1], y[n - 1], x[0], y[0])
	ans += cothalf(x[n - 1], y[n - 1], x[0], y[0], x[1], y[1])
	return ans

def perimeter(x, y, n):
	ans = 0
	for i in range(n - 1):
		ans += distance(x[i], y[i], x[i + 1], y[i + 1])
	ans += distance(x[0], y[0], x[n - 1], y[n - 1])
	return ans

def area(x, y, n):
	ans = 0
	for i in range(n - 1):
		ans += x[i] * y[i + 1] - y[i] * x[i + 1]
	ans += x[n - 1] * y[0] - y[n - 1] * x[0]
	ans /= 2
	if ans < 0:
		ans = -ans
	return ans
t = int(input())
for zz in range(t):
	nq = list(map(int, input().split()))
	n = nq[0]
	q = nq[1]
	x = []
	y = []
	for i in range(n):
		ttt = list(map(int, input().split()))
		x.append(ttt[0])
		y.append(ttt[1])
	ar = area(x, y, n)
	p = perimeter(x, y, n)
	cs = cotsum(x, y, n)
	for i in range(q):
		vt = list(map(int, input().split()))
		s = vt[0] * vt[1]
		ar += s * p + s * s * cs
		print(ar)
		ar -= s * p + s * s * cs


import math

def lengthBetweenPoints(p0, p1):
	return math.sqrt(pow(p0[0] - p1[0], 2) + pow(p0[1] - p1[1], 2))

def angleBetweenPoints(a, b, c):
	l0 = lengthBetweenPoints(a, b)
	l1 = lengthBetweenPoints(b, c)
	l2 = lengthBetweenPoints(a, c)
	return math.acos((l0 * l0 + l1 * l1 - l2 * l2) / (2 * l0 * l1))

def polygonArea(poly, n):
	area = 0.0
	j = n - 1
	for i in range(0, n):
		area += (poly[j][0] + poly[i][0]) * (poly[j][1] - poly[i][1])
		j = i
	return abs(area / 2.0)

def polygonPerimeter(poly, n):
	peri = 0
	for i in range(n):
		p0 = poly[i]
		p1 = poly[i + 1 if i != n - 1 else 0]
		length = lengthBetweenPoints(p0, p1)
		peri += length
	return peri

def polygonTriCot(poly, n):
	tricot = 0
	for i in range(n):
		a = poly[i - 1]
		b = poly[i]
		c = poly[i + 1 if i != n - 1 else 0]
		angle = angleBetweenPoints(a, b, c)
		tricot += 1 / math.tan(angle / 2)
	return tricot
for _ in range(int(input())):
	(N, Q) = map(int, input().split())
	poly = []
	for i in range(N):
		(x, y) = map(int, input().split())
		poly.append((x, y))
	poly_area = polygonArea(poly, N)
	poly_peri = polygonPerimeter(poly, N)
	poly_tric = polygonTriCot(poly, N)
	for i in range(Q):
		(v, t) = map(int, input().split())
		d = v * t
		print(poly_area + d * poly_peri + d * d * poly_tric)


import math
t = int(input().strip())

def cot(x):
	if x == 0:
		return 0
	t = math.tan(x)
	if t == 0:
		return 0
	else:
		return 1 / t
for _ in range(0, t):
	(N, Q) = map(int, input().strip().split())
	coords = []
	for _ in range(0, N):
		(x, y) = map(float, input().strip().split())
		coords.append((x, y))
	area = abs(sum([coords[i][0] * (coords[i + 1][1] - coords[i - 1][1]) for i in range(-1, N - 1)])) / 2.0
	perimeter = 0
	anglesT = 0
	for i in range(0, N):
		pi = i - 1
		ni = (i + 1) % N
		x0 = coords[pi][0]
		y0 = coords[pi][1]
		x1 = coords[i][0]
		y1 = coords[i][1]
		x2 = coords[ni][0]
		y2 = coords[ni][1]
		d1 = (x1 - x0) ** 2 + (y1 - y0) ** 2
		d2 = (x1 - x2) ** 2 + (y1 - y2) ** 2
		d3 = (x2 - x0) ** 2 + (y2 - y0) ** 2
		perimeter += math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
		angle = math.acos((d1 + d2 - d3) / (2 * math.sqrt(d1) * math.sqrt(d2)))
		anglesT += cot(angle / 2)
	for _ in range(0, Q):
		(v, t) = map(float, input().strip().split())
		dist = v * t
		a = perimeter * dist + dist ** 2 * anglesT
		print(area + a)


from math import sin, cos, acos

def polyArea(x, y):
	return 0.5 * np.abs(np.dot(x, np.roll(y, 1)) - np.dot(y, np.roll(x, 1)))

def euclideanDistance(A, B):
	return ((A[0] - B[0]) ** 2 + (A[1] - B[1]) ** 2) ** (1 / 2)

def angleVertix(O, A, B):
	module = euclideanDistance(A, O) * euclideanDistance(O, B)
	scalar = (O[0] - A[0]) * (O[0] - B[0]) + (O[1] - A[1]) * (O[1] - B[1])
	return acos(scalar / module)
T = int(input())
for _ in range(T):
	(N, Q) = map(int, input().split())
	anglesCoeffSum = 0
	perimeter = 0
	manualArea = 0
	vertices = []
	firstVertix = 0
	for n in range(N):
		(x, y) = map(int, input().split())
		vertices.append([x, y])
	for i in range(len(vertices)):
		v = vertices[i]
		prev = vertices[len(vertices) - 1]
		adj = vertices[0]
		if i != len(vertices) - 1:
			adj = vertices[i + 1]
		if i != 0:
			prev = vertices[i - 1]
		side = euclideanDistance(adj, v)
		perimeter += side
		a = angleVertix(v, prev, adj)
		anglesCoeffSum += 1 / sin(a) * (1 + cos(a))
		manualArea += v[0] * adj[1] - v[1] * adj[0]
	for q in range(Q):
		(t, v) = map(int, input().split())
		s = t * v
		print(abs(manualArea) / 2 + perimeter * s + anglesCoeffSum * s ** 2)


import sys
import math

def get_ints():
	return list(map(int, sys.stdin.readline().strip().split()))

def tr(a, n):
	return math.floor(a * 10 ** n) / 10 ** n
t = int(input())
for j in range(t):
	a = get_ints()
	x = []
	y = []
	for l in range(a[0]):
		r = get_ints()
		x.append(r[0])
		y.append(r[1])
	A = 0.0
	j = a[0] - 1
	for rr in range(a[0]):
		A += (x[j] + x[rr]) * (y[j] - y[rr])
		j = rr
	A = abs(A / 2.0)
	sum2 = 0.0
	for k in range(a[0] - 2):
		gy = (x[k] - x[k + 1]) * (-x[k + 1] + x[k + 2]) + (y[k] - y[k + 1]) * (-y[k + 1] + y[k + 2])
		n12 = (x[k] - x[k + 1]) ** 2 + (y[k] - y[k + 1]) ** 2
		n23 = (x[k + 2] - x[k + 1]) ** 2 + (y[k + 2] - y[k + 1]) ** 2
		angle = gy / (n12 * n23) ** 0.5
		act = math.acos(angle) / 2
		length1 = 1 / math.tan(act)
		sum2 = sum2 + length1
	gy = (x[a[0] - 2] - x[a[0] - 1]) * (-x[a[0] - 1] + x[0]) + (y[a[0] - 2] - y[a[0] - 1]) * (-y[a[0] - 1] + y[0])
	n12 = (x[a[0] - 2] - x[a[0] - 1]) ** 2 + (y[a[0] - 2] - y[a[0] - 1]) ** 2
	n23 = (-x[a[0] - 1] + x[0]) ** 2 + (-y[a[0] - 1] + y[0]) ** 2
	angle = gy / (n12 * n23) ** 0.5
	act = math.acos(angle) / 2
	length1 = 1 / math.tan(act)
	sum2 = sum2 + length1
	gy = (x[a[0] - 1] - x[0]) * (-x[0] + x[1]) + (y[a[0] - 1] - y[0]) * (-y[0] + y[1])
	n12 = (x[a[0] - 1] - x[0]) ** 2 + (y[a[0] - 1] - y[0]) ** 2
	n23 = (-x[0] + x[1]) ** 2 + (-y[0] + y[1]) ** 2
	angle = gy / (n12 * n23) ** 0.5
	act = math.acos(angle) / 2
	length1 = 1 / math.tan(act)
	sum2 = sum2 + length1
	psum = 0.0
	for ii in range(a[0] - 1):
		psum += ((x[ii] - x[ii + 1]) ** 2 + (y[ii] - y[ii + 1]) ** 2) ** 0.5
	psum += ((x[a[0] - 1] - x[0]) ** 2 + (y[a[0] - 1] - y[0]) ** 2) ** 0.5
	for k in range(a[1]):
		gg = get_ints()
		d = A + psum * gg[0] * gg[1] + sum2 * gg[0] * gg[0] * gg[1] * gg[1]
		print(d)


import math
T = int(input())
for a in range(T):
	(N, Q) = [int(x) for x in input().split()]
	(Ar, Das) = (list(), list())
	(a1, a2) = (0, 0)
	for i in range(N):
		I = [float(x) for x in input().split()]
		a1 += I[0]
		a2 += I[1]
		Ar.append(I)
	for i in range(Q):
		I = [float(x) for x in input().split()]
		Das.append(I[0] * I[1])
	c = [a1 / N, a2 / N]
	for i in range(N):
		Ar[i] = [Ar[i][0] - c[0], Ar[i][1] - c[1]]

	def P(x1, y1, x2, y2):
		if x1 - x2 == 0:
			return [x2, 0]
		else:
			m = (y2 - y1) / (x2 - x1)
			p = (m * x2 - y2) / (m * m + 1)
			return [m * p, -p]

	def mod(P):
		return math.sqrt(P[0] * P[0] + P[1] * P[1])

	def holla(x1, y1, x2, y2, x3, y3, P1, P2):
		mP1 = mod(P1)
		mP2 = mod(P2)
		if x2 - x1 == 0:
			(A, B) = (P1[0], P1[0] / mP1)
			m2 = (y3 - y2) / (x3 - x2)
			return [A, B, m2 * (A - P2[0]) + P2[1], m2 * B + (P2[1] - m2 * P2[0]) / mP2]
		elif x3 - x2 == 0:
			(A, B) = (P2[0], P2[0] / mP2)
			m1 = (y2 - y1) / (x2 - x1)
			return [A, B, m1 * (A - P1[0]) + P1[1], m1 * B + (P1[1] - m1 * P1[0]) / mP1]
		else:
			(m1, m2) = ((y2 - y1) / (x2 - x1), (y3 - y2) / (x3 - x2))
			A = (P2[1] - P1[1] - (m2 * P2[0] - m1 * P1[0])) / (m1 - m2)
			B = (P2[1] / mP2 - P1[1] / mP1 - (m2 * P2[0] / mP2 - m1 * P1[0] / mP1)) / (m1 - m2)
			C = m2 * (A - P2[0]) + P2[1]
			D = m2 * B + (P2[1] - m2 * P2[0]) / mP2
			return [A, B, C, D]
	Ar.append(Ar[0])
	Ar.append(Ar[1])
	Box = list()
	for k in range(N):
		P1 = P(Ar[k][0], Ar[k][1], Ar[k + 1][0], Ar[k + 1][1])
		P2 = P(Ar[k + 1][0], Ar[k + 1][1], Ar[k + 2][0], Ar[k + 2][1])
		Box.append(holla(Ar[k][0], Ar[k][1], Ar[k + 1][0], Ar[k + 1][1], Ar[k + 2][0], Ar[k + 2][1], P1, P2))
	Box.append(Box[0])
	(L1, L2, L3) = (0, 0, 0)
	for k in range(N):
		(A1, B1, C1, D1) = Box[k]
		(A2, B2, C2, D2) = Box[k + 1]
		L1 += A1 * C2 - C1 * A2
		L2 += A1 * D2 + B1 * C2 - (C1 * B2 + D1 * A2)
		L3 += B1 * D2 - D1 * B2
	for d in Das:
		print(0.5 * (L1 + L2 * d + L3 * d * d))


import math

def dist(x1, y1, x2, y2):
	return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** (1 / 2)

def cos_theta(a, b, c):
	return (b ** 2 + c ** 2 - a ** 2) / (2 * b * c)

def sin_theta(ct):
	return (1 - ct ** 2) ** (1 / 2)

def angle_area_factor(a, b, c):
	c = cos_theta(a, b, c)
	s = sin_theta(c)
	if round(s, 3) == 0:
		return 0
	else:
		return c / s + 1 / s
T = int(input())
for i in range(T):
	(N, Q) = [int(j) for j in input().split()]
	c_x = 0
	c_y = 0
	X = []
	Y = []
	for k in range(N):
		(x, y) = [int(l) for l in input().split()]
		X.append(x)
		Y.append(y)
		c_x += x
		c_y += y
	c_x /= N
	c_y /= N
	Tan_Inv = []
	flag = 0
	for m in range(N):
		Tan_Inv.append(math.atan2(Y[m] - c_y, X[m] - c_x))
	z = zip(Tan_Inv, X, Y)
	s = sorted(z)
	s.append(s[0])
	D = []
	Alt_D = []
	Area = 0
	for n in range(N):
		if n == 0:
			w0 = s[N - 1]
		else:
			w0 = s[n - 1]
		w1 = s[n]
		w2 = s[n + 1]
		D.append(dist(w1[1], w1[2], w2[1], w2[2]))
		Area += w1[1] * w2[2] - w2[1] * w1[2]
		Alt_D.append(dist(w0[1], w0[2], w2[1], w2[2]))
	Area /= 2
	perimeter = 0
	total_angle_area_factor = 0
	for o in range(N):
		a = Alt_D[o]
		b = D[o]
		if o == 0:
			c = D[N - 1]
		else:
			c = D[o - 1]
		total_angle_area_factor += angle_area_factor(a, b, c)
		perimeter += b
	for p in range(Q):
		(v, t) = [int(q) for q in input().split()]
		factor = v * t
		print(Area + perimeter * factor + total_angle_area_factor * factor ** 2)


from math import acos, sqrt, tan
T = int(input())
r = []
for j in range(T):
	[N, Q] = [int(k) for k in input().split()]
	x = []
	y = []
	for i1 in range(N):
		x1 = input().split()
		x.append(int(x1[0]))
		y.append(int(x1[1]))
	x = x + [x[0], x[1]]
	y = y + [y[0], y[1]]
	a1 = 0
	ts = 0
	ta = 0
	for i in range(N):
		a1 = a1 + (x[i] * y[i + 1] - x[i + 1] * y[i]) / 2
		a = sqrt((x[i] - x[i + 1]) ** 2 + (y[i] - y[i + 1]) ** 2)
		b = sqrt((x[i + 2] - x[i + 1]) ** 2 + (y[i + 2] - y[i + 1]) ** 2)
		dp = (x[i] - x[i + 1]) * (x[i + 2] - x[i + 1]) + (y[i] - y[i + 1]) * (y[i + 2] - y[i + 1])
		th = acos(dp / (a * b))
		ts = ts + a
		ta = ta + 1 / tan(th / 2)
	for i1 in range(Q):
		x1 = input().split()
		vt = int(x1[0]) * int(x1[1])
		r.append(vt * vt * ta + vt * ts + a1)
for res in r:
	print(res)


from math import tan, acos, sqrt

def dist(p, q):
	return sqrt(sum(((px - qx) ** 2.0 for (px, qx) in zip(p, q))))

def func(points):
	(x1, y1) = points[0]
	(x2, y2) = points[1]
	(x3, y3) = points[2]
	return 1 / tan(acos(((x3 - x2) * (x1 - x2) + (y3 - y2) * (y1 - y2)) / dist((x1, y1), (x2, y2)) / dist((x3, y3), (x2, y2))) / 2)
t = int(input())
for _ in range(t):
	(n, q) = (int(x) for x in input().split())
	points = [tuple((int(x) for x in input().split())) for _ in range(n)]
	cross = lambda a, b: a[0] * b[1] - b[0] * a[1]
	(lensum, area) = (dist(points[0], points[-1]), cross(points[-1], points[0]))
	for i in range(n - 1):
		lensum += dist(points[i + 1], points[i])
		area += cross(points[i], points[i + 1])
	cotanglesum = func((points[0], points[-1], points[-2])) + func((points[-1], points[0], points[1]))
	area = abs(area) / 2
	for i in range(n - 2):
		cotanglesum += func((points[i], points[i + 1], points[i + 2]))
	for _ in range(q):
		(v, t) = (int(x) for x in input().split())
		k = v * t
		print(area + k * lensum + k * k * cotanglesum)


import math

def getTangentOfExternalAngle(x1, y1, x0, y0, x2, y2):
	cosTheta = ((x1 - x0) * (x2 - x0) + (y1 - y0) * (y2 - y0)) / math.sqrt(((x1 - x0) ** 2 + (y1 - y0) ** 2) * ((x2 - x0) ** 2 + (y2 - y0) ** 2))
	tanTheta = math.sqrt((cosTheta + 1) / (1 - cosTheta))
	return tanTheta

def getAreaByCoordinates(x, y, n):
	area = 0
	for i in range(0, n - 1):
		area += x[i] * y[i + 1] - x[i + 1] * y[i]
	area += x[n - 1] * y[0] - x[0] * y[n - 1]
	area *= 0.5
	return area

def getTraversedArea(x, y, q, n, n_q, debug=False):
	sides = []
	sumOfSides = 0
	for i in range(0, n):
		side = math.sqrt((x[(i + 1) % n] - x[i]) ** 2 + (y[(i + 1) % n] - y[i]) ** 2)
		sides.append(side)
		sumOfSides += side
	tangets = []
	sumOfTangents = 0
	for i in range(0, n):
		tani = getTangentOfExternalAngle(x[(i - 1) % n], y[(i - 1) % n], x[i], y[i], x[(i + 1) % n], y[(i + 1) % n])
		tangets.append(tani)
		sumOfTangents += tani
	firstArea = getAreaByCoordinates(x, y, n)
	if debug:
		print('Sides: ', sides)
		print('Tangents: ', tangets)
	for i in range(n_q):
		(v, t) = q[i]
		d = v * t
		area = firstArea + d ** 2 * sumOfTangents + d * sumOfSides
		print('%.7f' % area)

def main():
	for _ in range(int(input())):
		(n, n_q) = map(int, input().split())
		x = [0] * n
		y = [0] * n
		q = [0] * n_q
		for i in range(n):
			(xi, yi) = map(int, input().split())
			x[i] = xi
			y[i] = yi
		for i in range(n_q):
			(v, t) = map(int, input().split())
			q[i] = (v, t)
		getTraversedArea(x, y, q, n, n_q)
main()


def area(vertices, n):
	area = 0.0
	j = n - 1
	for i in range(0, n):
		area += (vertices[j][0] + vertices[i][0]) * (vertices[j][1] - vertices[i][1])
		j = i
	return abs(area / 2.0)
t = int(input())
for _ in range(t):
	(n, q) = map(int, input().split())
	vertices = []
	for i in range(n):
		vertices.append(list(map(int, input().split())))
	original_area = area(vertices, n)
	cot_sum = 0
	perimeter = 0
	for i in range(n):
		x1 = vertices[i][0]
		y1 = vertices[i][1]
		x2 = vertices[(i + 1) % n][0]
		y2 = vertices[(i + 1) % n][1]
		x3 = vertices[(i + 2) % n][0]
		y3 = vertices[(i + 2) % n][1]
		a = ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5
		perimeter += a
		b = ((x3 - x2) ** 2 + (y3 - y2) ** 2) ** 0.5
		c = ((x3 - x1) ** 2 + (y3 - y1) ** 2) ** 0.5
		cosine = (a ** 2 + b ** 2 - c ** 2) / (2 * a * b)
		cot_sum += ((1 + cosine) / (1 - cosine)) ** 0.5
	for i in range(q):
		ans = original_area
		(v, t) = map(int, input().split())
		d = v * t
		ans += cot_sum * d ** 2 + perimeter * d
		print(ans)


from math import pi, sqrt, acos, sin, tan

def angle(v1, v2):
	a = acos((v1[0] * v2[0] + v1[1] * v2[1]) / (sqrt(v1[0] ** 2 + v1[1] ** 2) * sqrt(v2[0] ** 2 + v2[1] ** 2)))
	return a

def distance(x1, y1, x2, y2):
	return sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
for _ in range(int(input())):
	(n, q) = map(int, input().split())
	(X, Y) = ([], [])
	for _ in range(n):
		(xi, yi) = map(int, input().split())
		X.append(xi)
		Y.append(yi)
	(area, perimeter, inc_factor) = (0, 0, 0)
	j = n - 1
	for i in range(n):
		(vi, vj) = ([X[i] - X[i - 1], Y[i] - Y[i - 1]], [X[i] - X[(i + 1) % n], Y[i] - Y[(i + 1) % n]])
		theta = angle(vi, vj)
		inc_factor += 1 / sin(theta) + 1 * tan(pi / 2 - theta)
		perimeter += distance(X[i], Y[i], X[(i + 1) % n], Y[(i + 1) % n])
		area += (X[j] + X[i]) * (Y[j] - Y[i])
		j = i
	area = abs(area / 2)
	for _ in range(q):
		(vi, ti) = map(int, input().split())
		dis = vi * ti
		res = area + perimeter * dis + dis * dis * inc_factor
		print(res)


from sys import stdin, stdout

def findDistance(x, y):
	return math.sqrt(sum([(a - b) ** 2 for (a, b) in zip(x, y)]))

def areaOfTrapezoid(h, sum1, sum2):
	return 1 * sum1 * h + h * h * sum2

def polygonArea(X, Y, n):
	area = 0.0
	j = n - 1
	for i in range(0, n):
		area += (X[j] + X[i]) * (Y[j] - Y[i])
		j = i
	return abs(area / 2.0)
import math

def lengthSquare(X, Y):
	xDiff = X[0] - Y[0]
	yDiff = X[1] - Y[1]
	return xDiff * xDiff + yDiff * yDiff

def returnAngles(A, B, C):
	a2 = lengthSquare(B, C)
	b2 = lengthSquare(A, C)
	c2 = lengthSquare(A, B)
	a = math.sqrt(a2)
	b = math.sqrt(b2)
	c = math.sqrt(c2)
	alpha = math.acos((b2 + c2 - a2) / (2 * b * c))
	betta = math.acos((a2 + c2 - b2) / (2 * a * c))
	gamma = math.acos((a2 + b2 - c2) / (2 * a * b))
	return [alpha, betta, gamma]

def find_Centroid(v):
	ans = [0, 0]
	n = len(v)
	signedArea = 0
	for i in range(len(v)):
		x0 = v[i][0]
		y0 = v[i][1]
		x1 = v[(i + 1) % n][0]
		y1 = v[(i + 1) % n][1]
		A = x0 * y1 - x1 * y0
		signedArea += A
		ans[0] += (x0 + x1) * A
		ans[1] += (y0 + y1) * A
	signedArea *= 0.5
	ans[0] = ans[0] / (6 * signedArea)
	ans[1] = ans[1] / (6 * signedArea)
	return ans
t = int(stdin.readline().strip())
for _ in range(t):
	(n, q) = list(map(int, stdin.readline().strip().split()))
	vertices = list()
	vertexX = list()
	vertexY = list()
	for _ in range(n):
		vertex = list(map(int, stdin.readline().strip().split()))
		vertexX.append(vertex[0])
		vertexY.append(vertex[1])
		vertices.append(vertex)
	centroid = find_Centroid(vertices)
	angles = list()
	angles1 = list()
	distances = list()
	sum1 = 0
	sum2 = 0
	area = polygonArea(vertexX, vertexY, n)
	for i in range(n):
		(a, b, c) = (i - 1, i, i + 1)
		if i == 0:
			a = n - 1
		elif i == n - 1:
			c = 0
		temp11 = returnAngles(vertices[a], vertices[b], vertices[c])
		angles1.append(temp11[1])
	for i in range(n):
		if i == n - 1:
			y = 0
		else:
			y = i + 1
		temp1 = returnAngles(vertices[i], vertices[y], centroid)
		temp2 = findDistance(vertices[i], vertices[y])
		angles.append(temp1)
		distances.append(temp2)
	for i in range(n):
		sum1 = sum1 + distances[i]
		sum2 = sum2 + 1 / math.tan(angles1[i] / 2)
	for _ in range(q):
		(v, t) = list(map(int, stdin.readline().strip().split()))
		area1 = area + areaOfTrapezoid(v * t, sum1, sum2)
		print(area1)


import math
for _ in range(int(input())):
	(n, q) = map(int, input().split())
	xy = []
	for i in range(n):
		(x, y) = map(int, input().split())
		xy.append((x, y))
	p = 0
	cot = 0
	for i in range(n):
		(x1, y1) = xy[i]
		(x2, y2) = xy[(i + 1) % n]
		(x3, y3) = xy[(i + 2) % n]
		a = ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
		b = ((x3 - x2) ** 2 + (y3 - y2) ** 2) ** 0.5
		c = ((x1 - x3) ** 2 + (y1 - y3) ** 2) ** 0.5
		p += a
		p = p
		cos = (a ** 2 + b ** 2 - c ** 2) / (2 * a * b)
		cot += ((1 + cos) / (1 - cos)) ** 0.5
		cot = cot
	ians = 0.0
	j = n - 1
	for i in range(0, n):
		ians += (xy[j][0] + xy[i][0]) * (xy[j][1] - xy[i][1])
		j = i
	ians = abs(ians / 2.0)
	for i in range(q):
		ans = ians
		(v, t) = map(int, input().split())
		z = v * t
		ans += z * p
		ans = ans + z * z * cot
		print(ans)


import numpy as np
import sys
import time
start_time = time.time()
try:
	sys.stdin = open('input.txt', 'r')
except:
	pass
input = sys.stdin.readline

def area(x, y):
	return 0.5 * np.abs(np.dot(x, np.roll(y, 1)) - np.dot(y, np.roll(x, 1)))

def angle(b):
	a = np.roll(b, -1, axis=0)
	c = np.roll(b, 1, axis=0)
	return np.arctan2(c[:, 1] - b[:, 1], c[:, 0] - b[:, 0]) - np.arctan2(a[:, 1] - b[:, 1], a[:, 0] - b[:, 0])

def dist(p):
	return np.sqrt(((p - np.roll(p, 1, axis=0)) ** 2).sum(axis=1))
T = int(input())
for _ in range(T):
	(n, q) = map(int, input().split())
	p = np.ndarray((n, 2), dtype=np.float64)
	for i in range(n):
		p[i] = tuple(map(int, input().split()))
	a = area(*zip(*p))
	l = np.abs(1 / np.tan(angle(p) / 2)).sum()
	d = np.abs(dist(p)).sum()
	for i in range(q):
		(v, t) = map(int, input().split())
		print((v * t) ** 2 * l + v * t * d + a)


import math

def get_init_area(vertices):
	(res, length) = (0, len(vertices))
	for i in range(0, length):
		res += (vertices[i][0] + vertices[(i + 1) % length][0]) * (vertices[(i + 1) % length][1] - vertices[i][1])
	return abs(res) / 2

def get_sides(vertices):
	(sides, length) = ([], len(vertices))
	for i in range(0, length):
		y = vertices[(i + 1) % length][1] - vertices[i][1]
		x = vertices[(i + 1) % length][0] - vertices[i][0]
		sides.append(math.sqrt(y ** 2 + x ** 2))
	return sides

def get_slopes(vertices):
	(slopes, length) = ([], len(vertices))
	for i in range(0, length):
		y = vertices[(i + 1) % length][1] - vertices[i][1]
		x = vertices[(i + 1) % length][0] - vertices[i][0]
		slopes.append([x, y])
	return slopes

def get_angles(slopes):
	(angles, length) = ([], len(slopes))
	for i in range(0, length):
		num = slopes[i][1] * slopes[(i + 1) % length][0] - slopes[(i + 1) % length][1] * slopes[i][0]
		den = slopes[i][0] * slopes[(i + 1) % length][0] + slopes[i][1] * slopes[(i + 1) % length][1]
		if den == 0:
			angles.append(math.pi / 2)
		else:
			angle = math.atan(num / den)
			if angle < 0:
				angle += math.pi
			angles.append(angle)
	return angles

def get_tan_sum(angles):
	res = 0
	for angle in angles:
		res += math.cos(angle / 2) / math.sin(angle / 2)
	return res

def print_angles(angles):
	new_angles = []
	for angle in angles:
		new_angles.append(math.degrees(angle))
	print(new_angles)
	print('angle sum: ', sum(new_angles))
T = int(input())
for i in range(0, T):
	inp = list(map(int, input().split()))
	(N, Q) = (inp[0], inp[1])
	vertices = []
	for j in range(0, N):
		vertices.append(list(map(int, input().split())))
	area = get_init_area(vertices)
	sides = get_sides(vertices)
	slopes = get_slopes(vertices)
	angles = get_angles(slopes)
	perimeter = sum(sides)
	tan_sum = get_tan_sum(angles)
	for j in range(0, Q):
		inp = list(map(int, input().split()))
		d = inp[0] * inp[1]
		res_area = area
		res_area += perimeter * d
		res_area += d ** 2 * tan_sum
		print('{0:.7f}'.format(res_area))


from decimal import *
from math import *
import sys
getcontext().prec = 16
MAXN = 10005
coordX = [Decimal(0)] * MAXN
coordY = [Decimal(0)] * MAXN
vectrX = [Decimal(0)] * MAXN
vectrY = [Decimal(0)] * MAXN
lenSides = [Decimal(0)] * MAXN
Testcases = int(input())
for i in range(Testcases):
	(N, Q) = map(int, input().split())
	sumSides = Decimal(0)
	sumCot = Decimal(0)
	for i in range(N):
		(coordX[i], coordY[i]) = map(Decimal, input().split())
	area = Decimal(0)
	for i in range(N):
		h = coordX[(i + 1) % N] - coordX[i]
		b = coordY[(i + 1) % N] + coordY[i]
		area = area + h * b
		dx = coordX[(i + 1) % N] - coordX[i]
		dy = coordY[(i + 1) % N] - coordY[i]
		lenSides[i] = (dx * dx + dy * dy).sqrt()
		sumSides = sumSides + lenSides[i]
		vectrX[i] = dx
		vectrY[i] = dy
	for i in range(N):
		prod = vectrX[i] * vectrX[(i + 1) % N] + vectrY[i] * vectrY[(i + 1) % N]
		prodEsc = Decimal(prod) / Decimal(lenSides[i])
		cosAng = Decimal(prodEsc) / Decimal(lenSides[(i + 1) % N])
		cotMid = Decimal(Decimal(1) - cosAng) / Decimal(Decimal(1) + cosAng)
		cotMid = Decimal(cotMid).sqrt()
		sumCot = sumCot + cotMid
	if area < 0:
		area = -area
	area = area / 2
	for q in range(Q):
		(v, t) = map(Decimal, input().split())
		ans = area + v * t * sumSides + v * v * t * t * sumCot
		print(ans)


from heapq import heapify, heappush, heappop
from decimal import *
getcontext().prec = 19

def dif(b, a):
	return (b[0] - a[0], b[1] - a[1])

def cosprod(a, b):
	return a[0] * b[0] + a[1] * b[1]

def sinprod(a, b):
	return a[0] * b[1] - a[1] * b[0]

def norm(a):
	return Decimal.sqrt(a[0] * a[0] + a[1] * a[1])

def get_sum(pq):
	heapify(pq)
	while len(pq) > 1:
		heappush(pq, heappop(pq) + heappop(pq))
	return heappop(pq)
for tcase in range(int(input())):
	(n, q) = map(int, input().split())
	vertex = [tuple(map(Decimal, input().split()))]
	side = []
	sidelen = []
	for i in range(1, n):
		vertex.append(tuple(map(Decimal, input().split())))
		s = dif(vertex[i], vertex[i - 1])
		side.append(s)
		sidelen.append(norm(s))
	vertex.append(vertex[0])
	side.append(dif(vertex[n], vertex[n - 1]))
	sidelen.append(norm(side[n - 1]))
	side.append(side[0])
	sidelen.append(sidelen[0])
	perimeter = 0
	sum_tan_half_ext_ang = 0
	for i in range(1, n + 1):
		cop = cosprod(side[i - 1], side[i])
		sip = sinprod(side[i - 1], side[i])
		rec = sidelen[i - 1] * sidelen[i]
		perimeter += sidelen[i]
		if cop > 0:
			sum_tan_half_ext_ang += sip / (rec + cop)
		else:
			sum_tan_half_ext_ang += (rec - cop) / sip
	area = 0
	for i in range(1, n - 1):
		area += sinprod(side[i], dif(vertex[n], vertex[i]))
	area /= 2
	for i in range(q):
		(v, t) = map(int, input().split())
		height = v * t
		sum_medians = perimeter + sum_tan_half_ext_ang * height
		result = area + sum_medians * height
		print('{:.3f}'.format(result))


from heapq import heapify, heappush, heappop
from math import sqrt
from decimal import *

def dif(b, a):
	return (b[0] - a[0], b[1] - a[1])

def cosprod(a, b):
	return a[0] * b[0] + a[1] * b[1]

def sinprod(a, b):
	return a[0] * b[1] - a[1] * b[0]

def normsqr(a):
	return cosprod(a, a)

def get_sum(pq):
	heapify(pq)
	while len(pq) > 1:
		heappush(pq, heappop(pq) + heappop(pq))
	return heappop(pq)
for tcase in range(int(input())):
	(n, q) = map(int, input().split())
	vertex = [None] + [tuple(map(int, input().split())) for i in range(n)]
	vertex[0] = vertex[n]
	side = [dif(vertex[i + 1], vertex[i]) for i in range(n)]
	side.append(side[0])
	sidelensqr = [normsqr(side[i]) for i in range(n + 1)]
	perimeter = get_sum([sqrt(sidelensqr[i]) for i in range(1, n + 1)])
	pq = []
	for i in range(1, n + 1):
		cop = cosprod(side[i - 1], side[i])
		sip = sinprod(side[i - 1], side[i])
		rec = sqrt(Decimal(normsqr(side[i - 1]) * normsqr(side[i])))
		co = cop / rec
		si = sip / rec
		if co > 0.0:
			pq.append(si / (1.0 + co))
		else:
			pq.append((1.0 - co) / si)
	sum_tan_half_ext_ang = get_sum(pq)
	area = sum((sinprod(side[i], dif(vertex[n], vertex[i])) for i in range(1, n - 1))) / 2.0
	for i in range(q):
		(v, t) = map(int, input().split())
		height = v * t
		result = get_sum([area, perimeter * height, sum_tan_half_ext_ang * height * height])
		print('{:.3f}'.format(result))


from math import sqrt, acos, tan

def sidelen(A, B):
	return sqrt((A[0] - B[0]) ** 2 + (A[1] - B[1]) ** 2)
T = int(input())
for _ in range(T):
	(N, Q) = map(int, input().split())
	v = []
	for _ in range(N):
		(x, y) = map(int, input().split())
		v.append((x, y))
	v.append(v[0])
	v.append(v[1])
	base_area = 0
	perimeter = 0
	for i in range(N):
		base_area += v[i][0] * v[i + 1][1] - v[i][1] * v[i + 1][0]
		perimeter += sidelen(v[i], v[i + 1])
	base_area = abs(base_area)
	base_area = base_area / 2
	anglesum = 0
	for i in range(N):
		a = sidelen(v[i], v[i + 1])
		b = sidelen(v[i + 1], v[i + 2])
		c = sidelen(v[i + 2], v[i])
		beta = acos((a ** 2 + b ** 2 - c ** 2) / (2 * a * b))
		anglesum += 1 / tan(beta / 2)
	for j in range(Q):
		(v, t) = map(int, input().split())
		print(base_area + v * t * perimeter + (v * t) ** 2 * anglesum)


from heapq import heapify, heappush, heappop
from math import sqrt

def dif(b, a):
	return (b[0] - a[0], b[1] - a[1])

def cosprod(a, b):
	return a[0] * b[0] + a[1] * b[1]

def sinprod(a, b):
	return a[0] * b[1] - a[1] * b[0]

def normsqr(a):
	return cosprod(a, a)

def get_sum(pq):
	heapify(pq)
	while len(pq) > 1:
		heappush(pq, heappop(pq) + heappop(pq))
	return heappop(pq)
for tcase in range(int(input())):
	(n, q) = map(int, input().split())
	vertex = [None] + [tuple(map(int, input().split())) for i in range(n)]
	vertex[0] = vertex[n]
	side = [dif(vertex[i + 1], vertex[i]) for i in range(n)]
	side.append(side[0])
	sidelensqr = [normsqr(side[i]) for i in range(n + 1)]
	perimeter = get_sum([sqrt(sidelensqr[i]) for i in range(1, n + 1)])
	sum_tan_half_ext_ang = get_sum([sinprod(side[i - 1], side[i]) / (sqrt(normsqr(side[i - 1]) * normsqr(side[i])) + cosprod(side[i - 1], side[i])) for i in range(1, n + 1)])
	area = sum((sinprod(side[i], dif(vertex[n], vertex[i])) for i in range(1, n - 1))) / 2.0
	for i in range(q):
		(v, t) = map(int, input().split())
		height = v * t
		sum_medians = perimeter + sum_tan_half_ext_ang * height
		result = area + sum_medians * height
		print('{:.3f}'.format(result))


from math import sqrt

def dif(b, a):
	return (b[0] - a[0], b[1] - a[1])

def cosprod(a, b):
	return a[0] * b[0] + a[1] * b[1]

def sinprod(a, b):
	return a[0] * b[1] - a[1] * b[0]

def normsqr(a):
	return cosprod(a, a)
for tcase in range(int(input())):
	(n, q) = map(int, input().split())
	vertex = [None] + [tuple(map(int, input().split())) for i in range(n)]
	vertex[0] = vertex[n]
	side = [dif(vertex[i + 1], vertex[i]) for i in range(n)]
	side.append(side[0])
	sidelensqr = [normsqr(side[i]) for i in range(n + 1)]
	perimeter = sum((sqrt(sidelensqr[i]) for i in range(1, n + 1)))
	sum_tan_half_ext_ang = sum((sinprod(side[i - 1], side[i]) / (sqrt(normsqr(side[i - 1]) * normsqr(side[i])) + cosprod(side[i - 1], side[i])) for i in range(1, n + 1)))
	area = sum((sinprod(side[i], dif(vertex[n], vertex[i])) for i in range(1, n - 1))) / 2.0
	for i in range(q):
		(v, t) = map(int, input().split())
		height = v * t
		sum_medians = perimeter + sum_tan_half_ext_ang * height
		result = area + sum_medians * height
		print('{:.3f}'.format(result))


import sys
import math
from decimal import *

def pyt(x, y):
	return x * x + y * y

def cross(a, b):
	return a[0] * b[1] - a[1] * b[0]

def dot(a, b):
	return a[0] * b[0] + a[1] * b[1]

def norm(a):
	return dot(a, a)
getcontext().prec = 40
inp = [a.strip() for a in sys.stdin.readlines()]
T = int(inp[0])
line = 1
for _ in range(T):
	(n, Q) = [int(x) for x in inp[line].split()]
	line += 1
	(xs, ys) = (list(), list())
	for i in range(n):
		(x, y) = [int(x) for x in inp[line].split()]
		xs.append(x)
		ys.append(y)
		line += 1
	area = 0
	peri = Decimal(0)
	corners = Decimal(0)
	for i in range(n):
		j = (i + 1) % n
		area += (xs[i] - xs[j]) * (ys[i] + ys[j])
		peri += Decimal(pyt(xs[i] - xs[j], ys[i] - ys[j])).sqrt()
		k = (i + 2) % n
		a = (xs[i] - xs[j], ys[i] - ys[j])
		b = (xs[k] - xs[j], ys[k] - ys[j])
		sin = cross(b, a)
		if sin > 0:
			cos = dot(b, a)
			na = norm(a)
			nb = norm(b)
			corners += ((Decimal(na) * Decimal(nb)).sqrt() + Decimal(cos)) / Decimal(sin)
	A = Decimal(abs(area) / 2)
	P = peri
	C = corners
	for i in range(Q):
		(v, t) = [int(x) for x in inp[line].split()]
		D = Decimal(v * t)
		print(A + (P + C * D) * D)
		line += 1


import sys
import math
from decimal import *

def pyt(x: Decimal, y: Decimal) -> Decimal:
	return x * x + y * y

def cross(a, b):
	return a[0] * b[1] - a[1] * b[0]

def dot(a, b):
	return a[0] * b[0] + a[1] * b[1]

def norm(a):
	return dot(a, a)

def abs1(a):
	return norm(a).sqrt()
getcontext().prec = 20
inp = [a.strip() for a in sys.stdin.readlines()]
T = int(inp[0])
line = 1
for _ in range(T):
	(n, Q) = [int(x) for x in inp[line].split()]
	line += 1
	(xs, ys) = (list(), list())
	for i in range(n):
		(x, y) = [Decimal(x) for x in inp[line].split()]
		xs.append(x)
		ys.append(y)
		line += 1
	area = Decimal(0)
	peri = Decimal(0)
	corners = Decimal(0)
	for i in range(n):
		j = (i + 1) % n
		area = area + (xs[i] - xs[j]) * (ys[i] + ys[j])
		peri = peri + pyt(xs[i] - xs[j], ys[i] - ys[j]).sqrt()
		k = (i + 2) % n
		a = (xs[i] - xs[j], ys[i] - ys[j])
		b = (xs[k] - xs[j], ys[k] - ys[j])
		sin = cross(b, a)
		if sin > 0:
			cos = dot(b, a)
			ab = abs1(a) * abs1(b)
			corners = corners + (ab + cos) / sin
	area = abs(area) / 2
	for i in range(Q):
		(v, t) = [Decimal(x) for x in inp[line].split()]
		v *= t
		print(area + peri * v + corners * v * v)
		line += 1


from math import atan2, tan, hypot, pi

class Point:

	def __init__(self, x, y):
		self.x = x
		self.y = y

def solve():
	(n, q) = map(int, input().split())
	pt = []
	for _ in range(n):
		(x, y) = map(float, input().split())
		pt.append(Point(x, y))
	(psum, nsum) = (0, 0)
	total_len = 0
	tan_sum = 0
	for i in range(n):
		a = pt[i]
		b = pt[(i + 1) % n]
		c = pt[(i + 2) % n]
		psum += a.x * b.y
		nsum += a.y * b.x
		total_len += hypot(a.x - b.x, a.y - b.y)
		(ax, ay) = (b.x - a.x, b.y - a.y)
		(bx, by) = (c.x - b.x, c.y - b.y)
		la = hypot(ax, ay)
		lb = hypot(bx, by)
		ax /= la
		ay /= la
		bx /= lb
		by /= lb
		dot = ax * bx + ay * by
		det = ax * by - ay * bx
		angle = atan2(det, dot)
		tan_sum += tan(angle / 2)
	area = abs(psum - nsum) / 2
	for _ in range(q):
		(v, t) = map(int, input().split())
		dx = v * t
		print(area + total_len * dx + dx * dx * tan_sum)
for _ in range(int(input())):
	solve()


import math
t = int(input())
for i in range(0, t):
	(n, q) = map(int, input().split())
	V = []
	Q = []
	for j in range(0, n):
		(x, y) = map(int, input().split())
		V.append((x, y))
	base_area = 0
	peri = 0
	U = []
	E = []
	for j in range(0, n):
		e = (V[(j + 1) % n][0] - V[j][0], V[(j + 1) % n][1] - V[j][1])
		U.append(e)
		d1 = (e[0] ** 2 + e[1] ** 2) ** 0.5
		E.append(d1)
		base_area += (V[(j + 1) % n][0] - V[j][0]) * (V[(j + 1) % n][1] + V[j][1])
		peri += d1
	base_area = abs(base_area / 2)
	cosine = [0] * n
	for j in range(0, n):
		cosine[j] = (U[j][0] * U[(j + 1) % n][0] + U[j][1] * U[(j + 1) % n][1]) / (E[j] * E[(j + 1) % n])
	st = 0
	for j in range(0, n):
		temp = cosine[j]
		temp1 = ((1 - temp) / (temp + 1)) ** 0.5
		st += temp1
	for v in range(0, q):
		(v, t0) = map(int, input().split())
		d = v * t0
		area = base_area
		area += peri * d
		area += d * d * st
		print(area)


import sys
import math

def pyt(x, y):
	return x * x + y * y

def angle(a, b, c):
	return math.atan2(a[1] - b[1], a[0] - b[0]) - math.atan2(c[1] - b[1], c[0] - b[0])
inp = [a.strip() for a in sys.stdin.readlines()]
T = int(inp[0])
line = 1
for _ in range(T):
	(n, Q) = [int(x) for x in inp[line].split()]
	line += 1
	(xs, ys) = (list(), list())
	for i in range(n):
		(x, y) = [int(x) for x in inp[line].split()]
		xs.append(x)
		ys.append(y)
		line += 1
	area = 0
	peri = 0
	corners = 0
	for i in range(n):
		j = (i + 1) % n
		area += (xs[i] - xs[j]) * (ys[i] + ys[j])
		peri += math.sqrt(pyt(xs[i] - xs[j], ys[i] - ys[j]))
		k = (i + 2) % n
		ang = angle((xs[i], ys[i]), (xs[j], ys[j]), (xs[k], ys[k])) / 2
		opp = math.sin(ang)
		adj = math.cos(ang)
		corners += opp * adj
		corners += adj * adj * adj / opp
	area = abs(area) / 2
	for i in range(Q):
		(v, t) = [int(x) for x in inp[line].split()]
		v *= t
		print(area + peri * v + corners * v * v)
		line += 1