Pythagorean Expectation

No attempts yetTime limit1sMemory limit256 MB

Problem

The Pythagorean expectation has the same shape as the Pythagorean theorem and is used often in baseball and other sports. Bill James defined it, and it measures how well a team did over a season. For a baseball team the Pythagorean expectation WW is

W=S2S2+A2W = \frac{S^2}{S^2 + A^2}

where SS is the total number of runs the team scored and AA is the total number of runs it allowed.

Comparing this value with the real win rate tells you how the season went. Suppose a team scored 619 runs and allowed 889 runs in one season. Then S=619S = 619 and A=889A = 889, so W=6192/(6192+8892)=0.326W = 619^2 / (619^2 + 889^2) = 0.326. If every team plays 128 games in a season, that team was expected to win 0.326×128=41.7280.326 \times 128 = 41.728 games. Winning 49 games means the season went better than expected. A team with S=715S = 715 and A=719A = 719 has W=0.497W = 0.497 and was expected to win 0.497×128=63.6160.497 \times 128 = 63.616 games, so winning 58 falls short.

You are given the match records of nn teams. Compute the Pythagorean expectation of every team from those records, then print the largest and the smallest of them.

Input

Read from standard input. The first line holds the number of test data sets TT. The first line of each test data set holds the number of teams nn (2n10002 \le n \le 1000) and the total number of matches mm (2m10002 \le m \le 1000). Each of the next mm lines describes one match as four integers aa, bb, pp, qq: team aa played team bb, team aa scored pp runs and team bb scored qq runs. Here 1abn1 \le a \ne b \le n, and pp and qq are integers between 0 and 20. Teams inside one test data set do not have to play the same number of matches. If a team's total scored runs and total allowed runs are both 0, its expectation is defined as 0.

Output

Write to standard output. For each test data set print two integers, one per line. The first line holds the integer part of the maximum Pythagorean expectation multiplied by 1,000, and the second line holds the integer part of the minimum Pythagorean expectation multiplied by 1,000.