GCD on Tree

All submissions for this problem are available.
Given a tree with N nodes and N1 edges, where each edge has a weight associated with it.
Gcd(A,B) represents gcd of weights of all the edges in the path from A to B.
Len(A,B) is number of edges in path from A to B.
You have to find maximum value of Gcd(A,B) * Len(A,B) over all possible pair of nodes A,B.
Input
 The first line of the input contains an integer T denoting the number of test cases.
 The first line of each test case contains a single integer N denoting the number of nodes in the tree.
 Next N1 lines contains 3 integers a,b,c denoting that there is an edge between node a and b having weight c.
Output
 For each test case, output a single line containing the required answer.
Constraints
 1 ≤ T ≤ 10
 1 ≤ N ≤ 100000
 1 ≤ a,b ≤ N
 1 ≤ c ≤ 100000
Example
Input: 1 3 1 2 10 2 3 4 Output: 10
Explanation
There are 3 possible paths: f(1,2) = 10*1 = 10 f(2,3) = 4*1 = 4 f(1,3) = 2*2 = 4 So the maximum value is 10
Author:  skullcrackers 
Editorial  http://discuss.codechef.com/problems/GCDTREE 
Tags  centroiddecomp, datastructure, gcd, ipc151a, skullcrackers 
Date Added:  4102015 
Time Limit:  10 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, PYP3, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 