Chandan is a horrendous murderer and he wants to kill Arjit just because he's lazy.  Chandan is following the trail of Arjit's shoes. The trail is in the form of a k-ary tree. Arjit is lazy, sure, but he's smart. So, he magically moves away from Chandan as far as he can go.

Chandan doesn't know the way out, but he knows that Arjit has managed to travel the maximum distance he can. Help Chandan find out the maximum distance he would have to travel to find Arjit. And also tell him how much will he have to pay to travel so far. The travel rates are:
If maximum distance is <100, cost = 0.  
If maximum distance is > 100, cost = 100.  
If maximum distance is > 1000, cost = 1000.  
If maximum distance is > 10000, cost = 10000.

Input format:
First line contains the total number of test cases. Then, the next line contains the number of nodes. The the next n lines contain three integers - the first two denote an edge between a and b, the third integer denotes the weight of that edge.  

Output format:
You've to print the money Chandan will pay and the maximum distance he will have to travel.  

Constraints:
1 ≤ Test Cases ≤ 10
2 ≤ n ≤ 100000
1 ≤ a, b ≤ n
1 ≤ weight ≤ 100  

SAMPLE INPUT
1
5
1 2 4
3 2 3
2 5 2
4 1 1

SAMPLE OUTPUT
0 8
t=int(raw_input())
def bfs(x):
    b=[False]*(n+1)# an array of false flags to keep track of vertices visited
    memo=["p"]*(n+1)
    l=0
    c=0
    q=[]
    q.append(x)
    memo[x]=0
    while len(q)!=0:
        #t=s[-1]
        top=q.pop(0)
        #l=t
        b[top]=True
        #q.pop(0)
        for j in G[top]:
            #print j
            if memo[j[0]]=="p":
                q.append(j[0])
                memo[j[0]]=memo[top]+j[1]#time of discovery(level) of child is time of discovery(level) of parent+1
                b[j[0]]=True
                if memo[j[0]]>l:
                    l=memo[j[0]]
                    c=j[0]
                    
                #c+=1
    #return l,c
    #m=0
    #m_i=0
    #print memo
    #for i in xrange(0,n+1):
     # if type(memo[i])==int and memo[i]>m:
      #  m=memo[i]
       # m_i=i
    return l,c     
    
while t!=0:
    n=int(raw_input())
    G=[[] for i in xrange(n+1)]
    p=n-1
    while p!=0:
        x,y,z=map(int,raw_input().split())
        G[x].append((y,z))#undirected graph has edge from u to v.
        G[y].append((x,z))#alse has edge from v to u.
      
        p-=1
    upto,new=bfs(1)
    found=False
    while not found:
        #print upto,new
        #upto,new=bfs(new)
        j=bfs(new)
        #print j
        if upto<j[0]:
            upto=j[0]
            new=j[1]
        else:
            found=True
    if upto<100:
        print 0,upto
    if upto>100 and upto <1000:
        print 100,upto
    if upto>1000 and upto <10000:
        print 1000,upto
    if upto>10000:
        print 10000,upto        
            
    t-=1