We need to understand the problem statement. Harry wants the rectangle covering all points, with at least one edge parallel to the X-axis. So rectangle axes-aligned? Actually "at least one edge of the rectangle parallel to the Forbidden third floor corridor which is the X-axis." So at least one edge parallel to X-axis. That means the rectangle can be rotated as long as it has one side parallel to X-axis. But if rectangle has one side parallel to X-axis, then the rectangle is oriented such that its sides are either aligned with axes (if both sides parallel to axes) or one side is horizontal, the other side is at some angle? Wait: A rectangle has two pairs of parallel sides. If one side is parallel to X-axis, then its opposite side is also parallel to X-axis. So the rectangle has a horizontal orientation. Then the other pair of sides will be vertical? Actually if a rectangle has one side parallel to X-axis, the other sides must be perpendicular to that side to maintain right angles. In a rectangle, all angles are 90 degrees. So if one side is horizontal (parallel to X-axis), the adjacent sides must be vertical (i.e., parallel to Y-axis) because the only direction perpendicular to horizontal is vertical (in Euclidean plane). However, if the rectangle is rotated, then none of the sides are horizontal. But the condition says "at least one edge of the rectangle parallel to the X-axis." So we can have rectangle with sides horizontal and vertical. In standard computational geometry, the minimal axis-aligned rectangle (bounding box) would satisfy that (both sides parallel to axes). But could there be a rotated rectangle that also has a horizontal side but not vertical? Actually if a rectangle is rotated, all sides are at some angle. The only way for one side to be parallel to X-axis is if the rectangle is not rotated (i.e., axis-aligned) because if one side is horizontal, then the adjacent side must be perpendicular to it, i.e., vertical. So the rectangle is axis-aligned. But wait: Could a rectangle be placed such that one side is horizontal and the other sides are not vertical? Consider a rectangle: by definition, all angles are 90 degrees. If one side is horizontal, then a side adjacent to it must be at 90 degrees to the horizontal, i.e., vertical. So yes, it must be vertical. Therefore the rectangle is axis-aligned. So it's just the minimal axis-aligned bounding rectangle. So area = (max_x - min_x) * (max_y - min_y). But the problem says "minimum possible rectangle that will cover all the points" with at least one edge parallel to X-axis. So if it's axis-aligned, that is the minimal area among all rectangles that have one side horizontal? But could there be a rectangle that is not axis-aligned but still has a horizontal side? As argued, if it has a horizontal side, it is axis-aligned. So yes, it's the axis-aligned rectangle.
But wait, the sample:
Test case 1: points (1,1) and (3,3). Then min area = (3-1)(3-1)=4. Output 4. OK.
Test case 2: points (1,1),(2,2),(2,3). The bounding box: min_x=1, max_x=2, min_y=1, max_y=3 => area = (2-1)(3-1)=2. Output 2. OK.
So seems straightforward. But there is a twist: "Incase your answer turns out to be zero, tell Harry the maximum possible length that can be obtained on joining all the points." So if area is zero, meaning all points are collinear (either horizontally or vertically?). Actually area zero would occur if either dx=0 or dy=0, i.e., all points have same x or same y, so the bounding rectangle degenerates to a line segment. Then we output the maximum possible length that can be obtained on joining all the points. That is the maximum distance between any two points (the diameter of the set) i.e., the length of the longest line segment among the points. So we need to compute the maximum Euclidean distance between any two points when area = 0. However, the phrase "maximum possible length that can be obtained on joining all the points" might be ambiguous: it could mean the length of the line segment covering all points? But if points are collinear, the minimal rectangle covering them is a degenerate rectangle (line). The "maximum possible length" probably refers to the length of the longest segment that can be formed by joining any two points. That's typical.
But careful: If area is zero, but not all points collinear? Actually area zero occurs if either width (max_x-min_x) = 0 or height (max_y-min_y) = 0. But that means all points share same x or same y. In such a case, the points are collinear along a vertical or horizontal line. They might not be collinear in general orientation? Actually if all x equal, they lie on a vertical line; all y equal, they lie on a horizontal line. Those are collinear. But what about points that are collinear but not aligned to axes? Example: points (0,0), (1,1), (2,2). Then min_x=0, max_x=2, min_y=0, max_y=2, area=4. So area not zero. So the only cases where area zero are when points are collinear and the line is either horizontal or vertical. But if the line is slanted, area > 0 because both x and y vary. But the condition for area zero is that either the width or height is zero. However, the problem states "Incase your answer turns out to be zero, tell Harry the maximum possible length that can be obtained on joining all the points." That indicates that they consider area = 0 when the rectangle degenerates to a line or a point. Possibly, they also consider the case where all points are same point? Then area zero, and max length is 0. So we need to output that length.
But wait: Could there be a case where area zero because min_x = max_x, but points have varying y? That yields vertical line; maximum length = max_y - min_y. Similarly, if min_y = max_y, then horizontal line; length = max_x - min_x. If both width and height zero (all points identical), length = 0.
Now the problem constraints: T up to 1000, N up to 1000, coordinates in small range. So straightforward solution: For each test case, read N points, compute min_x, max_x, min_y, max_y. Compute area = (max_x - min_x) * (max_y - min_y). If area != 0, output area. Else, compute the maximum distance between any two points. But careful: Is it necessary to compute distance only when area=0? Probably yes. But could there be other cases where area=0 but the maximal distance is not simply the range? For vertical line, distance = sqrt((0)^2 + (dy)^2) = |dy|, so it's just the difference in y. For horizontal line, difference in x. So Euclidean distance equals absolute difference. So we can compute the maximum difference along that axis. But wait, what if both width and height are zero? Then max distance = 0. So basically: If width == 0 and height > 0, max distance = height. If height == 0 and width > 0, max distance = width. If both 0, max distance = 0. But is that correct? Let's consider if points are collinear but not axis-aligned: area > 0, so we don't need to output length. So it's fine.
But what about the possibility of rectangle being rotated such that area is smaller than axis-aligned? The condition says at least one edge parallel to X-axis, which forces axis-aligned as argued. So we just need axis-aligned bounding box.
Thus the solution is trivial: compute bounding box, area = (max_x - min_x) * (max_y - min_y). If area == 0, compute max distance among points (maybe we need Euclidean distance? But if area zero, the points are collinear vertically or horizontally, so max distance is just the range; but could there be degenerate case where width=0 and height=0? That's a point). However, the problem statement says "maximum possible length that can be obtained on joining all the points." That could be interpreted as the length of the line segment that covers all points, i.e., the distance between the two farthest points. For a set of points on a line (vertical or horizontal), it's the difference in coordinates. For all points same, it's 0. So we can compute the maximum Euclidean distance between any two points (i.e., diameter). Since coordinates are integers and range small, we can compute O(N^2) for each test case when area=0. N up to 1000, T up to 1000, worst-case all tests area=0 => 10001000^2=1e9, too high. So we need to optimize. But we can notice that when area=0, points are collinear either horizontally (all y same) or vertically (all x same). In those cases, the farthest distance is simply (max_x - min_x) for horizontal, or (max_y - min_y) for vertical. For both zero, it's 0. So we can compute that in O(N) as part of bounding box. So no need for O(N^2). But is there any scenario where area=0 but points are not all with same x or same y? Let's check: area=0 means (max_x - min_x)(max_y - min_y)=0, so either width=0 or height=0. If width=0, all points share same x, but y can vary. That's a vertical line. Similarly height=0 -> horizontal line. So it's correct. So we can compute max distance as max( max_x-min_x, max_y-min_y ). But careful: If both width and height are zero, then it's 0. So length = max(width, height) because the Euclidean distance between farthest points is sqrt(dx^2+dy^2) but if one of dx,dy is 0, it's just the other. So indeed length = max(width, height). So we can output that.
But wait: Could there be scenario where width > 0 and height > 0 but area computed as zero due to integer overflow? No, area computed as product; zero only if one factor zero.
Thus algorithm: For each test case:
- Initialize min_x = INF, max_x = -INF, min_y = INF, max_y = -INF.
- Read N points, update.
- Compute width = max_x - min_x, height = max_y - min_y.
- area = width * height.
- If area != 0: print area.
- else: print max(width, height). (Since area zero, at least one of width,height is zero, so max gives the non-zero one, or zero if both zero).
But need to confirm with sample: Test2 area=1*2=2, not zero, print 2. ok.
Edge cases: N=2 points with same x but different y: width=0, height>0 => area=0, output max(0,height)=height. That is the distance between them (vertical). That seems correct as "maximum possible length that can be obtained on joining all the points". If points (1,1) and (1,3) => output 2. Euclidean distance = 2. Good.
If points (1,1) and (3,1): width=2, height=0 => output 2. Good.
If all points same: (0,0) repeated N times: width=0, height=0 => area=0 => output 0. Good.
But what about points that are collinear but not axis-aligned? Then area > 0, so we output area. Is that correct? Consider points (0,0), (1,1), (2,2). The minimal axis-aligned rectangle area = (2-0)*(2-0)=4. But could there be a rectangle with one side parallel to X-axis that has smaller area covering these points? Possibly a rotated rectangle? But we argued that if one side is horizontal, rectangle is axis-aligned. So the rectangle must have sides horizontal and vertical. So the bounding box is the smallest axis-aligned rectangle. So area=4. Could there be a rectangle that is not axis-aligned but has one side horizontal? That forces it to be axis-aligned. So yes.
Thus solution is trivial.
But wait, the problem statement: "Your task is to calculate the area of the minimum possible rectangle that will cover all the points that Malfoy has visited throughout the year with atleast one edge of the rectangle parallel to the Forbidden third floor corridor which is the X-axis." This might be interpreted as: the rectangle must have at least one edge parallel to X-axis, but it can be rotated such that one pair of edges is parallel to X-axis, while the other pair is not necessarily perpendicular to X-axis? That would not be a rectangle because then adjacent edges would not be perpendicular. So it's not a rectangle. So yes, the rectangle is axis-aligned. So it's simple.
Let's verify with more testcases: Suppose points (0,0), (2,1), (4,2). They are collinear with slope 0.5. Axis-aligned bounding box: width=4, height=2 => area=8. Could we have a smaller rectangle covering all points with one horizontal side? Maybe a rectangle that is rotated? But must have horizontal side, so rectangle is axis-aligned, so area=8. Could there be a rectangle with one side horizontal but not necessarily vertical that still covers the points? Consider rectangle with corners: (0,0), (a,0), (a,b), (0,b) rotated? No. If rectangle is rotated, its sides are at angles. If we enforce one side horizontal, then it's axis-aligned. So no.
Thus straightforward.
But the problem may be from a contest and might have trick: Actually sometimes "minimum area rectangle covering all points with at least one side parallel to x-axis" might allow the rectangle to be oriented arbitrarily as long as one side is horizontal. But if rectangle is rotated, the condition that one side is horizontal does not force the other side to be vertical? Yes it does because rectangle has right angles. So the other side must be perpendicular, i.e., vertical. So it's axis-aligned. So it's just bounding box.
Given constraints, answer should be integer because coordinates are integers. Area is integer, and max distance is integer when points are vertical/horizontal (difference). But is it always integer? For vertical/horizontal distances, it's integer difference. So output integer.
But the problem might expect output as integer, as per sample.
Now, let's consider the possibility of T up to 1000, N up to 1000. The straightforward O(N) per test case is fine (max 1e6 points total across all testcases, but note that T could be 1000 and N could be 1000 each, so total points up to 1e6, which is okay in C++/Python? In Python, reading 1e6 lines is doable with sys.stdin. But need to be efficient. Should be fine.
But wait, there is another nuance: "Incase your answer turns out to be zero, tell Harry the maximum possible length that can be obtained on joining all the points." The phrase "joining all the points" could be interpreted as the length of a path that goes through all points (like the total length of line segments joining all points). But "maximum possible length that can be obtained on joining all the points" is ambiguous. It could mean "the maximum length of a line segment that can be formed by joining any two of the points" i.e., the farthest pair. That is typical. Or it could mean "the length of the line that covers all points when joined" i.e., the length of the minimal line segment covering all points, which is the same as the farthest pair distance if collinear. Since the points are collinear when area zero, the minimal segment covering all points is indeed the distance between the min and max point along that line. So it's the same as max distance between any two points. So our interpretation stands.
Thus solution is simple.
But wait: Could there be scenario where width=0 and height>0, but the maximum distance is not simply height? Suppose points: (1,0), (1,5), (1,10). The maximum distance between any two is 10 (10-0) = 10, which equals height. So yes.
If points are (1,0), (1,5), (1,5) duplicate, still max distance =5? Actually max distance = max_y - min_y = 5, farthest points are (1,0) and (1,5) distance 5. So height works.
If both width and height are 0, then all points same, max distance = 0.
Thus answer is correct.
Now implement.
But need to double-check constraints: X between -90 and 90, Y between -180 and 180. So product area up to (180)* (360) ? Actually max width = 180, max height=360, area up to 64800, fits in int.
Now ensure output format: each test case output on separate line.
Now, is there any scenario where rectangle area is zero but we need to output something else? For example, if points are not all collinear but bounding box area is zero only if all points share x or y. So okay.
We should also note that points may not be unique. That's fine.
Thus implementation in Python:
def solve():
import sys
data = sys.stdin.read().strip().split()
if not data:
return
it = iter(data)
T = int(next(it))
out_lines = []
for _ in range(T):
N = int(next(it))
min_x = 91 # > 90
max_x = -91
min_y = 181
max_y = -181
for i in range(N):
x = int(next(it)); y = int(next(it))
if x < min_x: min_x = x
if x > max_x: max_x = x
if y < min_y: min_y = y
if y > max_y: max_y = y
width = max_x - min_x
height = max_y - min_y
area = width * height
if area != 0:
out_lines.append(str(area))
else:
# max distance = max(width, height) because one is zero
# But if both zero, output 0.
out_lines.append(str(max(width, height)))
sys.stdout.write("\n".join(out_lines))
But need to be careful: area = width * height could be negative? No, width and height are non-negative because max >= min. So area >= 0.
Potential edge: if N=0? But constraints N>=2. So okay.
Test with sample:
Input:
2
2
1 1
3 3
3
1 1
2 2
2 3
Our code:
Test1: min_x=1, max_x=3 => width=2; min_y=1, max_y=3 => height=2; area=4 => output 4.
Test2: min_x=1, max_x=2 => width=1; min_y=1, max_y=3 => height=2; area=2 => output 2.
Matches.
Now let's think: Could there be a scenario where width=0, height>0, but the maximum distance is actually something else? Suppose points: (0,0), (0,5), (0,10). Euclidean distance between (0,0) and (0,10) is 10, equal to height. So correct.
Now, is there any hidden nuance: "minimum possible rectangle that will cover all the points" - with at least one edge parallel to x-axis. Could there be a rectangle that is not axis-aligned but still has one edge horizontal? That is contradictory as we argued. But wait: A rectangle is defined as a quadrilateral with four right angles. So if one side is horizontal, then the adjacent sides must be vertical. So it's axis-aligned. So yes.
But what if the rectangle can be placed in 3D? No.
Thus solution stands.
Given the simplicity, why is this problem given? Maybe there is a twist: The rectangle may be rotated, but the condition is "at least one edge parallel to the X-axis". Could it be that the rectangle's sides are not necessarily aligned with the axes, but we can choose a rectangle that is rotated such that one side is horizontal, but the rectangle's other sides are not vertical because we might allow the rectangle to be not necessarily axis-aligned with the coordinate axes? Wait, again, rectangle has right angles. If one side is horizontal, the side adjacent to it must be perpendicular to it, i.e., vertical. So that side is parallel to Y-axis. So the rectangle is axis-aligned. So there is no alternative orientation.
But maybe the problem statement originally meant "with sides parallel to the axes"? But it says "at least one edge parallel to X-axis". So it's essentially axis-aligned.
Thus I'll go with this.
Now I'm going to produce final answer.
But before final, I want to consider if there is any scenario where area is zero but maximum distance is not simply max(width, height) because the points could be collinear but not axis-aligned? That case gives area > 0 as said. So not needed.
Therefore, final code is simple.
Now, provide answer with explanation.
However, given the AI nature, we need to produce final answer: Provide code in Python.
Also, note that the problem may require handling large T efficiently. Use sys.stdin.
Thus final answer.
We'll also include comments.
Now, I'll write final response. ```python
import sys
def solve() -> None:
data = sys.stdin.buffer.read().split()
if not data:
return
it = iter(data)
t = int(next(it))
out = []
for _ in range(t):
n = int(next(it))
# initialise with values outside the given coordinate ranges
min_x = 91 # > 90
max_x = -91
min_y = 181 # > 180
max_y = -181
for _ in range(n):
x = int(next(it))
y = int(next(it))
if x < min_x:
min_x = x
if x > max_x:
max_x = x
if y < min_y:
min_y = y
if y > max_y:
max_y = y
width = max_x - min_x
height = max_y - min_y
area = width * height
if area != 0:
out.append(str(area))
else:
# When area = 0, the points lie on a vertical or horizontal line
# (or all are the same). The farthest distance is simply the larger
# of width and height.
out.append(str(max(width, height)))
sys.stdout.write("\n".join(out))
if name == "main":
solve()