#P7819. Exam

Exam

Exam

Problem Description

You have to take nn exams, the exam ii was held in two periods of time, [aa, aa + atat] and [bb, bb + btbt] and you can take any one of the two periods to pass exam ii. But note that you cannot take two different exams at the same time. For example, it is impossible to take the first exam at [3,5][3,5] and take the second exam at [5,8][5,8]. \textbf{And note that for one exam}, the two periods of time may intersect, that is, [a, a+at][b, b+bt][a,\ a+at] \cap [b,\ b+bt] \ne \emptyset is also possible. Now, you want to pass all the nn exams as soon as possible. Print the earlist time when the last exam was finished if you can pass all the nn exams or print 1-1 if you can not pass all the exams.

Input

The first line contains a single integer TT denoting the number of test cases. For each test case, the first line contains a single integer nn (1n250001\leq n \leq 25000). The next nn lines contain four integers each: aa, atat, bb, btbt (0a, at, b, bt1090\leq a,\ at,\ b,\ bt \leq 10^{9} and n105\sum n \le 10^5)

Output

For each test case, output the only line containing just one integer denoting the answer if there would be, or 1-1 otherwise.

Sample Input

4
2
1 5 5 10
1 3 7 2
3
5 0 13 0
1 0 5 0
1 0 7 0
3
10 7 40 1
40 5 80 15
10 20 80 6
3
1 0 2 0
1 0 2 0
1 0 2 0

Sample Output

9
7
86
-1

Source

2020 Multi-University Training Contest 5