#P1916G. Optimizations From Chelsu
Optimizations From Chelsu
No submission language available for this problem.
Description
You are given a tree with vertices, whose vertices are numbered from to . Each edge is labeled with some integer .
Define as the number of edges in the simple path between vertices and , and as the Greatest Common Divisor of all numbers written on the edges of the simple path between vertices and . For example, and for any .
You need to find the maximum value of over all pairs of vertices in the tree.
Each test consists of multiple test cases. The first line contains a single integer () — the number of test cases. This is followed by their description.
The first line of each test case contains the number () — the number of vertices in the tree.
The next lines specify the edges in the format , , (, ).
It is guaranteed that the sum of over all test cases does not exceed .
For each test case, output a single number equal to the maximum value of over all pairs of vertices in the tree.
Input
Each test consists of multiple test cases. The first line contains a single integer () — the number of test cases. This is followed by their description.
The first line of each test case contains the number () — the number of vertices in the tree.
The next lines specify the edges in the format , , (, ).
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, output a single number equal to the maximum value of over all pairs of vertices in the tree.