Divisor Game

No attempts yetTime limit1sMemory limit128 MB

Problem

Bajtuś and Bituś are playing a new game. At the start, a single integer NN (with N>1N > 1) is written on the board. The players move alternately: on each move the current player replaces the number on the board with one of its divisors that is different from the number itself. The instant a player writes the number 11, the game ends.

For every divisor dd of NN other than NN itself, two fixed values a(d)a(d) and b(d)b(d) are given. Whenever Bajtuś writes dd on the board he scores a(d)a(d) points, and whenever Bituś writes dd he scores b(d)b(d) points. Each player plays to maximize his own advantage, that is, the difference between his own total score and his opponent's total score.

Bituś has already fixed NN and all of the scores. Bajtuś, in turn, gets to decide which of the two boys makes the first move. Assuming both play optimally, determine the advantage of the starting player in each of the two cases: when Bajtuś starts, and when Bituś starts.

Input

The first line contains a positive integer tt, the number of test cases. The test cases follow.

Each test case begins with a line of four integers n1n_1, n2n_2, n3n_3 and DD (1ni51061 \le n_i \le 5 \cdot 10^6, 1<n1n2n3810181 < n_1 n_2 n_3 \le 8 \cdot 10^{18}). Their product N=n1n2n3N = n_1 \cdot n_2 \cdot n_3 is the number initially written on the board, and DD is the number of positive divisors of NN.

The next D1D - 1 lines give the scores of the divisors of NN other than NN, listed in increasing order of the divisor. The ii-th of these lines contains two integers a(d)a(d) and b(d)b(d) (109a(d),b(d)109-10^9 \le a(d), b(d) \le 10^9), the points awarded to Bajtuś and to Bituś respectively for writing dd, where dd is the ii-th smallest divisor of NN.

The sum of DD over all test cases does not exceed 10610^6.

Output

For each test case print one line with two integers AA and BB. AA is the advantage of the starting player when Bajtuś moves first, and BB is the advantage of the starting player when Bituś moves first, both under optimal play.

Note

In the first sample test case N=7N = 7 is prime, so the starting player can only write 11, which ends the game at once and awards that player the score attached to 11. In the second sample test case N=4N = 4: the player to move prefers to write 22 and leave the opponent as the one forced to write 11.