This page is still under construction.

Parts of this page are still being built. What you see may change.

Frodo's Gift Wrapping

Time limit1sMemory limit256 MB

Summary
Three rotatable rectangles must be packed axis-aligned into one enclosing rectangle of smallest area.
Level

Medium4 of 10

Topics
Brute force, Geometry
Solved
No attempts yet

Problem

Frodo bought three birthday presents for Neo. Each present sits in its own rectangular gift box. Frodo wants to put all three gift boxes into a single rectangular wrapping box. A bigger wrapping box costs more, so he wants the one with the smallest area.

The size of the wrapping box depends on how the gift boxes are placed. The placement rules are:

  • Every side of a gift box is parallel to a side of the wrapping box.
  • Each gift box lies entirely inside the wrapping box, and no two gift boxes overlap.
  • A gift box is allowed to touch the border of the wrapping box.
  • A gift box can be rotated by 90 degrees.

For example, take gift boxes whose width ×\times height is 3×43 \times 4, 5×65 \times 6, and 4×14 \times 1. Placed as in the picture below, they need a wrapping box of size 8×8=648 \times 8 = 64.

Placed as in the next picture, the same three boxes need only a wrapping box of size 5×10=505 \times 10 = 50.

Given the sizes of the three gift boxes, find the smallest area of a wrapping box that safely holds all three.

Input

The first line contains the number of test cases TT (1≤T≤100001 \le T \le 10000).

Each test case consists of three lines. Each line contains two integers AA and BB (1≤A,B≤501 \le A, B \le 50), the width and the height of one gift box, separated by a space.

Output

For each test case, print on its own line the smallest area of a wrapping box that holds all three gift boxes.

Examples2

  1. Example 1

    Input
    2
    3 4
    5 6
    4 1
    3 3
    2 2
    1 1
    
    Expected output
    50
    15
    
  2. Example 2

    Input
    1
    1 1
    1 1
    1 1
    
    Expected output
    3