One day mum asked Petya to sort his toys and get rid of some of them. Petya found a whole box of toy spiders. They were quite dear to him and the boy didn't want to throw them away. Petya conjured a cunning plan: he will glue all the spiders together and attach them to the ceiling. Besides, Petya knows that the lower the spiders will hang, the more mum is going to like it and then she won't throw his favourite toys away. Help Petya carry out the plan.

A spider consists of *k* beads tied together by *k* - 1 threads. Each thread connects two different beads, at that any pair of beads that make up a spider is either directly connected by a thread, or is connected via some chain of threads and beads.

Petya may glue spiders together directly gluing their beads. The length of each thread equals 1. The sizes of the beads can be neglected. That's why we can consider that gluing spiders happens by identifying some of the beads (see the picture). Besides, the construction resulting from the gluing process should also represent a spider, that is, it should have the given features. 

After Petya glues all spiders together, he measures the length of the resulting toy. The distance between a pair of beads is identified as the total length of the threads that connect these two beads. The length of the resulting construction is the largest distance between all pairs of beads. Petya wants to make the spider whose length is as much as possible.

The picture two shows two spiders from the second sample. We can glue to the bead number 2 of the first spider the bead number 1 of the second spider. The threads in the spiders that form the sequence of threads of maximum lengths are highlighted on the picture.
The first input file line contains one integer *n* (1 ≤ *n* ≤ 100) — the number of spiders. Next *n* lines contain the descriptions of each spider: integer *n*<sub class="lower-index">*i*</sub> (2 ≤ *n*<sub class="lower-index">*i*</sub> ≤ 100) — the number of beads, then *n*<sub class="lower-index">*i*</sub> - 1 pairs of numbers denoting the numbers of the beads connected by threads. The beads that make up each spider are numbered from 1 to *n*<sub class="lower-index">*i*</sub>.
1
3 1 2 2 3
2
2
3 1 2 1 3
4 1 2 2 3 2 4
4
2
5 1 2 2 3 3 4 3 5
7 3 4 1 2 2 4 4 6 2 7 6 5
7
3
3 1 2 2 3
5 2 5 5 3 3 4 5 1
9 6 5 5 9 4 8 4 7 2 1 2 6 2 4 6 3
10
7
2 2 1
4 1 4 2 3 1 2
3 3 1 3 2
5 1 4 3 5 1 2 1 3
6 4 5 1 3 4 2 3 6 5 1
7 1 3 3 6 7 4 7 1 5 2 3 5
10 6 8 2 6 6 3 2 7 2 4 6 10 3 1 6 5 6 9
23
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25 34 25 18 31 50 21 6 32 19 19 28 22 42 39 25 22 26 21 40 21 33 21 39 14 43 3 15 17 2 19 12 26 24 28 5 22 11 4 20 10 45 48 36 4 22 4 32 4 31 39 49
10
4
10 9 5 9 7 7 6 7 2 1 4 9 1 7 3 2 10 3 8
10 9 10 2 5 3 6 5 7 9 3 9 1 9 2 2 8 2 4
10 5 3 2 5 1 6 6 8 3 9 3 10 5 1 8 4 3 7
10 7 6 3 1 8 10 2 3 2 7 5 9 10 5 1 4 2 8
23
import sys
sys.stdin=open('input.txt','r')
sys.stdout=open('output.txt','w')
n=int(input())
length=0
def dfs(x,p):
    len=0
    for i in graph[x]:
        if i!=p:
            len=max(len,dfs(i,x)+1)
    return len
for i in range(n):
    max_len=1
    list=[int(i) for i in input().split()]
    vertex_num=list[0]
    graph = [[] for i in range(vertex_num + 1)]
    for j in range(1,vertex_num*2-1,2):
        graph[list[j]]+=[list[j+1]]
        graph[list[j+1]]+=[list[j]]
    for k in range(1,vertex_num+1):
        max_len=max(max_len,dfs(k,0))
    length+=max_len
print(length)
sys.stdin.close()
sys.stdout.close()
