This page is still under construction.

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

Rectangle and Squares

Time limit2sMemory limit512 MB

Summary
Given target area A*B and a square size C, find the rectangle of side C that is closest in area to A*B, breaking ties toward the smaller area.
Level

Medium6 of 10

Topics
Math, Number theory, Brute force, Implementation
Solved
No attempts yet

Problem

Elijah visited his friend Phil and saw a rectangle with sides AA and BB. Elijah had wanted a rectangle of that area for a long time.

Back home, Elijah found that he owns a large number of squares of size C×CC \times C. He wants to build a rectangle out of those squares whose area is as close as possible to the area of Phil's rectangle. In other words, he wants to minimize the absolute difference between the two areas.

Elijah puts the squares down with their sides parallel, without gaps and without overlaps. He uses at least one square.

For example, if Phil's rectangle is 4×54 \times 5 and Elijah's squares are 3×33 \times 3, the rectangle with the closest area that Elijah can build is 3×63 \times 6.

Input

The first line contains the number of test cases tt (1≤t≤10 0001 \le t \le 10\,000).

Each of the next tt lines contains three integers AA, BB and CC (1≤A,B,C≤1091 \le A, B, C \le 10^9).

Output

For each test case print one line with the area of the rectangle Elijah builds.

If several areas are equally close to the area of Phil's rectangle, print the smallest of them.

Examples3

  1. Example 1

    Input
    3
    4 5 3
    2 3 1
    6 4 5
    
    Expected output
    18
    6
    25
    
  2. Example 2

    Input
    1
    1 1 1
    
    Expected output
    1
    
  3. Example 3

    Input
    5
    5 5 3
    6 6 3
    7 7 4
    11 1 3
    13 1 3
    
    Expected output
    27
    36
    48
    9
    9