The days of jokes are over!
Our beloved leader Pepe has become the supreme leader of Pepeland. As his first great decision, he has decided to eliminate all the noobs and fools from Pepeland. Only the smartest ones may remain!
To find out who is truly smart enough to stay, Pepe decides to create the riddle of the century. For this, he seeks the help of the smartest person on Earth, Woumya.
Pepe takes Woumya to a huge dungeon in Pepeland, where Dali and Sesh are trapped. The dungeon consists of $$$n$$$ rooms connected by $$$n - 1$$$ bidirectional corridors, forming a tree structure (a connected graph with no cycles). Each room has a number written on it, where the number written on room $$$i$$$ is $$$A_i$$$.
A path in the dungeon from room $$$u$$$ to room $$$v$$$ is defined as a sequence of distinct rooms $$$p_1,p_2,\ldots,p_m$$$ such that $$$p_1=u$$$, $$$p_m=v$$$, and $$$p_i$$$ and $$$p_{i+1}$$$ are directly connected by a corridor for all $$$1 \leq i \lt m$$$.
Woumya can choose any path through the dungeon. Suppose the path contains the rooms $$$u_1,u_2,\ldots,u_k$$$ in this order.
The beauty of this path is defined as
$$$$$$ \sum_{i=1}^{k} \gcd(A_{u_1},A_{u_2},\ldots,A_{u_i}). $$$$$$
Woumya wants to impress Pepe by finding the path with the maximum possible beauty. A path containing only a single room is also allowed.
Your task is to calculate the maximum possible beauty.
The input is read from standard input in the following format:
Each test file contains multiple test cases. The first line of the input contains the number of test cases $$$T$$$. Then, for each test case, the input is given in the following format:
For each test case, output a single integer — the maximum possible beauty of any route through the dungeon.
Constraints
| Subtask | Points | $$$\boldsymbol{n}$$$ | $$$\boldsymbol{A_i}$$$ | Additional Constraints |
| 0 | 0 | – | – | The examples |
| 1 | 10 | $$$\le 10^5$$$ | $$$\le 10^4$$$ | Every room is directly connected to a room $$$r$$$ by a corridor where $$$1 \le r \le n$$$. |
| 2 | 15 | $$$\le 1000$$$ | $$$\le 10^4$$$ | No additional constraints. |
| 3 | 75 | $$$\le 10^5$$$ | $$$\le 10^4$$$ | No additional constraints. |
1429 26 19 281 22 33 4
32
167 10 2 15 9 61 21 31 53 43 6
18
364669 9654 8331 3885 9651 78061 22 33 44 51 61089 23 34 72 41 3 60 99 48 971 21 33 44 52 66 73 82 97 10479 26 19 781 22 33 4
9663 105 82
Example 1
Input
1
4
29 26 19 28
1 2
2 3
3 4
Output
32
Explanation
The optimal path is from room $$$1$$$ to $$$4$$$ where the rooms are $$$1, 2, 3, 4$$$ in order. Hence, the maximum beauty is $$$\gcd(A_1) + \gcd(A_1, A_2) + \gcd(A_1, A_2, A_3) + \gcd(A_1, A_2, A_3, A_4) = \gcd(29) + \gcd(29,26) + \gcd(29,26,19) + \gcd(29,26,19,28) = 32.$$$
Example 2
Input
1
6
7 10 2 15 9 6
1 2
1 3
1 5
3 4
3 6
Output
18
Explanation
The optimal path is from room $$$4$$$ to room $$$2$$$, where the rooms are $$$4,3,1,2$$$ in order. Hence, the maximum beauty is
The optimal path is from room $$$4$$$ to $$$2$$$ where the rooms are $$$4, 3, 1, 2$$$ in order. Hence, the maximum beauty is $$$\gcd(A_4) + \gcd(A_4, A_3) + \gcd(A_4. A_3, A_1) + \gcd(A_4, A_3, A_1, A_2)=\gcd (15) + \gcd ( 15, 2) + \gcd(15, 2, 7) + \gcd(15,2,7,10) = 18.$$$