#include<bits/stdc++.h>
using namespace std;
int main(){
    long long t;
    cin>>t;
    while(t--){
        long long n,k,c=0,i;
        cin>>n>>k;
        vector<int> v;
        long long a[n];
        for( i=0;i<n;i++){
        cin>>a[i];
        if(a[i]%2!=0){
            c++;
            v.push_back(i+1);
        }
        }
        if(c>k){
            cout<<"YES"<<endl;
            for( i=1;i<k-1;i++)
            cout<<v[i]<<" ";
            if(v[v.size()-1]!=n)
            cout<<n;
            cout<<endl;
        }
        else if(c==k){
            cout<<"YES"<<endl;
        for(int i=0;i<k-1;i++)
        cout<<v[i]<<" ";
        if(v[v.size()-1]==n)
        cout<<n;
        cout<<endl;
        }
        else
        cout<<"NO"<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int q, n, k;
vector<int> v;
int main()
{
    cin >> q;
    for(int T = 0; T < q; T++)
    {
        cin >> n >> k;
        if(k%2) cout << "YES" << endl;
        else
        {
            for(int i = 0; i < n; i++)
            {
                int throwaway;
                cin >> throwaway;
            }
            cout << "NO" << endl;
            continue;
        }
        int ct = 0, kgz = 0;
        v.clear();
        for(int i = 0; i < n; i++)
        {
            int a;
            cin >> a;
            if(ct >= k-1) continue;
            kgz += a;
            if(kgz%2)
            {
                ct++;
                v.push_back(i+1);
                kgz=0;
            }
        }
        v.push_back(n);
        for(int kaz : v) cout << kaz << " ";
        v.clear();
        cout << endl;
    }
}


#include <bits/stdc++.h>

using namespace std;

int q, n, k;
vector<int> v;
int main()
{
    cin >> q;
    for(int T = 0; T < q; T++)
    {
        cin >> n >> k;
        if(k%2) cout << "YES" << endl;
        else
        {
            for(int i = 0; i < n; i++)
            {
                int throwaway;
                cin >> throwaway;
            }
            cout << "NO" << endl;
            continue;
        }
        int ct = 0, kgz = 0;
        v.clear();
        for(int i = 0; i < n; i++)
        {
            if(ct == k-1) break;
            int a;
            cin >> a;
            kgz += a;
            if(kgz%2)
            {
                ct++;
                v.push_back(i);
                kgz=0;
            }
        }
        for(int kaz : v) cout << kaz << " ";
        cout << endl;
    }
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

int q, n, k;
vector<int> v;
signed main()
{
    cin >> q;
    for(int T = 0; T < q; T++)
    {
        cin >> n >> k;
        if(k%2) cout << "YES" << endl;
        else
        {
            for(int i = 0; i < n; i++)
            {
                int throwaway;
                cin >> throwaway;
            }
            cout << "NO" << endl;
            continue;
        }
        int ct = 0, kgz = 0;
        v.clear();
        for(int i = 0; i < n; i++)
        {
            int a;
            cin >> a;
            kgz += a;
            if(ct >= k-1) continue;
            if(kgz%2)
            {
                ct++;
                v.push_back(i+1);
                kgz=0;
            }
        }
        if(kgz%2 == 0)
        {
            cout << "NO" << endl;
            continue;
        }
        v.push_back(n);
        for(int kaz : v) cout << kaz << " ";
        v.clear();
        cout << endl;
    }
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

int q, n, k;
vector<int> v;
signed main()
{
    cin >> q;
    for(int T = 0; T < q; T++)
    {
        cin >> n >> k;
        if(k%2) cout << "YES" << endl;
        else
        {
            for(int i = 0; i < n; i++)
            {
                int throwaway;
                cin >> throwaway;
            }
            cout << "NO" << endl;
            continue;
        }
        int ct = 0, kgz = 0;
        v.clear();
        for(int i = 0; i < n; i++)
        {
            int a;
            cin >> a;
            if(ct >= k-1) continue;
            kgz += a;
            if(kgz%2)
            {
                ct++;
                v.push_back(i+1);
                kgz=0;
            }
        }
        v.push_back(n);
        for(int kaz : v) cout << kaz << " ";
        v.clear();
        cout << endl;
    }
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

int q, n, k;
vector<int> v;
signed main()
{
    cin >> q;
    for(int T = 0; T < q; T++)
    {
        cin >> n >> k;
        if(k%2) cout << "YES" << endl;
        else
        {
            for(int i = 0; i < n; i++)
            {
                int throwaway;
                cin >> throwaway;
            }
            cout << "NO" << endl;
            continue;
        }
        int ct = 0, kgz = 0;
        v.clear();
        for(int i = 0; i < n; i++)
        {
            int a;
            cin >> a;
            if(ct >= k-1) continue;
            kgz += a;
            if(kgz%2)
            {
                ct++;
                v.push_back(i+1);
                kgz=0;
            }
        }
        if(kgz%2 == 0)
        {
            cout << "NO" << endl;
            continue;
        }
        v.push_back(n);
        for(int kaz : v) cout << kaz << " ";
        v.clear();
        cout << endl;
    }
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

int q, n, k;
vector<int> v;
signed main()
{
    cin >> q;
    for(int T = 0; T < q; T++)
    {
        cin >> n >> k;
        if(k%2)
        {
            // nothing
        }
        else
        {
            for(int i = 0; i < n; i++)
            {
                int throwaway;
                cin >> throwaway;
            }
            cout << "NO" << endl;
            continue;
        }
        int ct = 0, kgz = 0;
        v.clear();
        for(int i = 0; i < n; i++)
        {
            int a;
            cin >> a;
            kgz += a;
            if(ct >= k-1) continue;
            if(kgz%2)
            {
                ct++;
                v.push_back(i+1);
                kgz=0;
            }
        }
        if(kgz%2 == 0)
        {
            cout << "NO" << endl;
            continue;
        }
        cout << "YES" << endl;
        v.push_back(n);
        for(int kaz : v) cout << kaz << " ";
        v.clear();
        cout << endl;
    }
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

int q, n, k;
vector<int> v;
signed main()
{
    cin >> q;
    for(int i = 0; i < q; i++)
    {
        v.clear();
        cin >> n >> k;
        for(int i = 0; i < n; i++)
        {
            int a;
            cin >> a;
            if(a%2) v.push_back(i+1);
        }
        if(v.size() < k)
        {
            cout << "NO" << endl;
        } else if(v.size() % 2 != k % 2)
        {
            cout << "NO" << endl;
        } else
        {
            cout << "YES" << endl;
            for(int i = 0; i < k; i++)
            {
                cout << v[i] << " ";
            }
            cout << endl;
        }
    }
}


#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;
int res,n,re,t,x,y;
vector <int> a[111];
int visit(int x,int y){
	int m1=0,m2=0;
	for(int i=1;i<=int(a[x].size());i++){
		int u=a[x][i];
		if (y==u) continue;
		int z=visit(u,x)+1;
		if (x>m1) m2=m1,m1=z;
		else if (z>m2) m2=z;
	}
	re=max(m1+m2,re);
	return m1;
}
int main(){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
		for(int i=1;i<=n;i++)
			a[i].clear();
		for(int i=1;i<=n;i++){
			scanf("%d%d",&x,&y);
			a[x].push_back(y);
			a[y].push_back(x);
		}
		re=0;
		visit(1,0);
		res+=re;
	}
	cout<<res;
	return 0;
}


#include <iostream>
#include <vector>
using namespace std;
int res,n,re,t,x,y;
vector <int> a[111];
int visit(int x,int y){
	int m1=0,m2=0;
	for(int i=1;i<=int(a[x].size());i++){
		int u=a[x][i];
		if (y==u) continue;
		int z=visit(u,x)+1;
		if (x>m1) m2=m1,m1=z;
		else if (z>m2) m2=z;
	}
	re=max(m1+m2,re);
	return m1;
}
int main(){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin>>t;
	while(t--){
		cin>>n;
		for(int i=1;i<=n;i++)
			a[i].clear();
		for(int i=1;i<=n;i++){
			cin>>x>>y;
			a[x].push_back(y);
			a[y].push_back(x);
		}
		re=0;
		visit(1,0);
		res+=re;
	}
	cout<<res;
	return 0;
}


#include <iostream>
#include <vector>
using namespace std;
int ans,n,an,t,x,y;
vector <int> a[111];
int visit(int x,int y){
	int m1=0,m2=0;
	for(int i=1;i<=int(a[x].size());i++){
		int u=a[x][i];
		if (y==u) continue;
		int z=visit(u,x)+1;
		if (x>m1) m2=m1,m1=z;
		else if (z>m2) m2=z;
	}
	an=max(m1+m2,an);
	return m1;
}
int main(){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin>>t;
	while(t--){
		cin>>n;
		for(int i=1;i<=n;i++)
			a[i].clear();
		for(int i=1;i<=n;i++){
			cin>>x>>y;
			a[x].push_back(y);
			a[y].push_back(x);
		}
		an=0;
		visit(1,0);
		ans+=an;
	}
	cout<<ans;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cstring>
using namespace std;
int f1,f2,t,n,a[111],b[111],x,y,r;
vector <int> g[111];
int bfs(int x){
	memset(a,255,sizeof(a));
	a[x]=0;
	b[0]=x;
	f1=0;
	f2=1;
	while (f1<f2){
		int i=b[f1++];
		for(int j=0;j<int(g[i].size());j++){
			int k=g[i][j];
			if (a[k]==-1){a[k]=a[i]+1;b[f2++]=k;}
		}
	}
}
int main(){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin>>n;
	while (n--){
		cin>>t;
		for(int i=1;i<=n;i++)
			g[i].clear();
		while(t--){
			cin>>x>>y;
			g[x].push_back(y);
			g[y].push_back(x);
		}
		bfs(1);
		bfs(b[f2-1]);
		r+=a[b[f2-1]];
	}
	cout<<r<<endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;
int res,n,re,t,x,y;
vector <int> a[111];
int visit(int x,int y){
	int m1=0,m2=0;
	for(int i=1;i<=int(a[x].size());i++){
		int u=a[x][i];
		if (y==u) continue;
		int z=visit(u,x)+1;
		if (x>m1) m2=m1,m1=z;
		else if (z>m2) m2=z;
	}
	re=max(m1+m2,re);
	return m1;
}
int main(){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
		for(int i=1;i<=n;i++)
			a[i].clear();
		for(int i=1;i<=n;i++){
			scanf("%d%d",&x,&y);
			a[x].push_back(y);
			a[y].push_back(x);
		}
		re=0;
		visit(1,0);
		res+=re;
	}
	printf("%d",res);
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
long long large=1<<29;
int f[100][100];
int main(){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	int res=0,t,n,m,x,y;
	cin>>t;
	while(t--){
		cin>>n;
		m=n-1;
		for(int u=0;u<n;u++)
			for(int v=0;v<n;v++)
				if (u==v) f[u][v]=0; else f[u][v]=large;
		for(int i=0;i<m;i++){
			cin>>x>>y;
			x--;
			y--;
			f[x][y]=f[y][x]=1;
		}
		for(int k=0;k<n;k++)
			for(int i=0;i<n;i++)
				for(int j=0;j<n;j++)
					f[i][j]=min(f[i][j],f[i][k]+f[k][j]);
		int t=0;
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
				if (f[i][j]<large) t=max(t,f[i][j]);
		res+=t;
	}
	cout<<res;
	return 0;
}


#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
using namespace std;
int res,n,r,t,x,y;
vector <int> a[111];
int visit(int x,int p){
	int m1=0,m2=0;
	for(int i=0;i<int(a[x].size());i++){
		int y=a[x][i];
		if (y==p) continue;
		int z=visit(y,x)+1;
		if (z>m1) m2=m1,m1=z;
		else if (z>m2) m2=z;
	}
	r=max(m1+m2,r);
	return m1;
}
int main(){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
		for(int i=1;i<=n;i++)
			a[i].clear();
		for(int i=1;i<n;i++){
			scanf("%d%d",&x,&y);
			a[x].push_back(y);
			a[y].push_back(x);
		}
		r=0;
		visit(1,0);
		res+=r;
	}
	printf("%d",res);
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cstring>
using namespace std;
int f1,f2,t,n,a[111],b[111],x,y,r;
vector <int> g[111];
int bfs(int x){
	memset(a,255,sizeof(a));
	a[x]=0;
	b[0]=x;
	f1=0;
	f2=1;
	while (f1<f2){
		int i=b[f1++];
		for(int j=0;j<g[i].size();j++){
			int k=g[i][j];
			if (a[k]==-1){a[k]=a[i]+1;b[f2++]=k;}
		}
	}
}
int main(){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin>>t;
	while (t--){
		cin>>n;
		for(int i=1;i<=n;i++)
			g[i].clear();
		for(int i=1;i<n;i++){
			cin>>x>>y;
			g[x].push_back(y);
			g[y].push_back(x);
		}
		bfs(1);
		bfs(b[f2-1]);
		r+=a[b[f2-1]];
	}
	cout<<r<<endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
using namespace std;
int res,n,re,t,x,y;
vector <int> a[111];
int visit(int x,int y){
	int m1=0,m2=0;
	for(int i=0;i<int(a[x].size());i++){
		int u=a[x][i];
		if (y==u) continue;
		int z=visit(u,x)+1;
		if (x>m1) m2=m1,m1=z;
		else if (z>m2) m2=z;
	}
	re=max(m1+m2,re);
	return m1;
}
int main(){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
		for(int i=1;i<=n;i++)
			a[i].clear();
		for(int i=1;i<=n;i++){
			scanf("%d%d",&x,&y);
			a[x].push_back(y);
			a[y].push_back(x);
		}
		re=0;
		visit(1,0);
		res+=re;
	}
	printf("%d",res);
	return 0;
}


#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <queue>
#include <utility>
#include <set>

using namespace std;

const int V = 111, E = 211;

int head[V], to[E], next[E], d[V], visit[V];

int en;

void add_e(int v, int u)
{
	++en;
	to[en] = u;
	next[en] = head[v];
	head[v] = en;
}

void build()
{
	en = -1;
	for(int i = 0 ; i < V; ++i)
	{
		d[i] = to[i] = head[i] = next[i] =  -1;
		visit[i] = 0;
	}

}

void bfs(int v)
{
	d[v] = 0;
	queue <int> q;
	q.push(v);
	while(!q.empty())
	{
		int t = q.front(); q.pop();
		for(int i = head[t]; i != -1; i = next[i])
		{
			if(!visit[to[i]])
			{
				d[to[i]] = d[t] + 1;
				visit[to[i]] =1;
				q.push(to[i]);
			}
		}
	}

}

int main()
{
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);

	int n; scanf("%d", &n);

	int *sp = new int[n];

	for(int i = 0 ; i < n; ++i)
	{

		int k, u, v;
		scanf("%d", &k);
		build();

		for(int j = 0; j < k-1; ++j)
		{
			scanf("%d %d", &v, &u);
			add_e(v,u);
			add_e(u,v);
		}

		bfs(1);

		int max = 1;
		for(int j = 2; j <= k; ++j)
			if(d[max] < d[i])
				max = j;
		//printf("%d ", max);
		for(int j = 0; j < V; ++j)
		{
			d[j] = -1;
			visit[j] = 0;
		}

		bfs(max);

		int tmax = 1;
		for(int j = 2; j <= k; ++j)
			if(d[tmax] < d[j])
				tmax = j;
				;
		sp[i] = d[tmax];
	}

	int ans = 0;
	for(int i = 0; i < n; ++i)
		ans += sp[i];
	printf("%d", ans);
	return 0;
}


#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <queue>
#include <utility>
#include <set>

using namespace std;

const int V = 111, E = 211, INF = 100000;

int head[V], to[E], next[E], d[V], visit[V];

int en;

void add_e(int v, int u)
{
	++en;
	to[en] = u;
	next[en] = head[v];
	head[v] = en;
}

void build()
{
	en = -1;
	for(int i = 0 ; i < V; ++i)
	{
		d[i] = INF;
		to[i] = head[i] = next[i] =  -1;
		visit[i] = 0;
	}

}

void bfs(int v)
{
	d[v] = 0;
	visit[v] = 1;

	queue <int> q;
	q.push(v);
	while(!q.empty())
	{
		int t = q.front(); q.pop();
		for(int i = head[t]; i != -1; i = next[i])
		{
			if(!visit[to[i]])
			{
				d[to[i]] = d[t] + 1;
				visit[to[i]] = 1;
				q.push(to[i]);
			}
		}
	}

}

int main()
{
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);

	int n; scanf("%d", &n);

	int *sp = new int[n];

	for(int i = 0 ; i < n; ++i)
	{

		int k, u, v;
		scanf("%d", &k);
		build();

		for(int j = 0; j < k-1; ++j)
		{
			scanf("%d %d", &v, &u);
			add_e(v,u);
			add_e(u,v);
		}

		bfs(1);

		//for(int j = 1; j <= k; ++j)
			//printf("%d ", d[j]);

		int max = 1;
		for(int j = 2; j <= k; ++j)
			if(d[max] < d[i])
				max = j;

		for(int j = 0; j < V; ++j)
		{
			d[j] = -1;
			visit[j] = 0;
		}

		bfs(max);

		int tmax = 1;
		for(int j = 2; j <= k; ++j)
			if(d[tmax] < d[j])
				tmax = j;

		sp[i] = d[tmax];
	}

	int ans = 0;
	for(int i = 0; i < n; ++i)
		ans += sp[i];
	printf("%d", ans);
	return 0;
}


#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <queue>
#include <utility>
#include <set>

using namespace std;

const int V = 111, E = 211;

int head[V], to[E], next[E], d[V], visit[V];

int en;

void add_e(int v, int u)
{
	++en;
	to[en] = u;
	next[en] = head[v];
	head[v] = en;
}

void build()
{
	en = -1;
	for(int i = 0 ; i < V; ++i)
	{
		d[i] = to[i] = head[i] = next[i] =  -1;
		visit[i] = 0;
	}

}

void bfs(int v)
{
	d[v] = 0;
	visit[v] = 1;
	queue <int> q;
	q.push(v);
	while(!q.empty())
	{
		int t = q.front(); q.pop();
		for(int i = head[t]; i != -1; i = next[i])
		{
			if(!visit[to[i]])
			{
				d[to[i]] = d[t] + 1;
				visit[to[i]] =1;
				q.push(to[i]);
			}
		}
	}

}

int main()
{
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);

	int n; scanf("%d", &n);

	int *sp = new int[n];

	for(int i = 0 ; i < n; ++i)
	{

		int k, u, v;
		scanf("%d", &k);
		build();

		for(int j = 0; j < k-1; ++j)
		{
			scanf("%d %d", &v, &u);
			add_e(v,u);
			add_e(u,v);
		}

		bfs(1);

		//for(int j = 1; j <= k; ++j)
			//printf("%d ", d[j]);

		int max = 1;
		for(int j = 2; j <= k; ++j)
			if(d[max] < d[i])
				max = j;

		for(int j = 0; j < V; ++j)
		{
			d[j] = -1;
			visit[j] = 0;
		}

		bfs(max);

		int tmax = 1;
		for(int j = 2; j <= k; ++j)
			if(d[tmax] < d[j])
				tmax = j;

		sp[i] = d[tmax];
	}

	int ans = 0;
	for(int i = 0; i < n; ++i)
		ans += sp[i];
	printf("%d", ans);
	return 0;
}


#include <stdlib.h>
#include <stdio.h>

typedef long long  ll;

void swap(ll &a, ll &b)
{
	ll t = a; a = b; b = t;
}

const int N = 93;

ll fib[N];

int main()
{
	ll i , j , k, ai, aj; scanf("%lld %lld %lld %lld %lld", &i, &j, &k, &ai, &aj);

	if(i > j)
	{
		swap(ai,aj);
		swap(i,j);
	}

	fib[0] = fib[1] = fib[2] = 1;

	for(int t = 3; t < N; ++t)
		fib[t] = fib[t-1] + fib[t-2];

	ll prai = (aj - fib[j-i+1] * ai) / fib[j-i];

	//printf("%lld\n", prai);

	ll a = ai, b = prai, c;

	if(k >= i)
	{
		for(int t = 0 ;t < k - i; ++t)
		{
			c = a + b;
			b = a;
			a = c;
		}
		printf("%lld", a);
		return 0;

	}
	else
	{
		for(int t = 0; t < i - k - 1; ++t)
		{
			c = a - b;
			a = b;
			b = c;
		}

		printf("%lld",b);
		return 0;

	}
	return 0;

}


#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <queue>
#include <utility>
#include <set>

using namespace std;

const int V = 111, E = 211, INF = 100000;

int head[V], to[E], next[E], d[V], visit[V];

int en;

void add_e(int v, int u)
{
	++en;
	to[en] = u;
	next[en] = head[v];
	head[v] = en;
}

void build()
{
	en = -1;
	for(int i = 0 ; i < V; ++i)
	{
		d[i] = INF;
		to[i] = head[i] = next[i] =  -1;
		visit[i] = 0;
	}

}

void bfs(int v)
{
	d[v] = 0;
	visit[v] = 1;

	queue <int> q;
	q.push(v);
	while(!q.empty())
	{
		int t = q.front(); q.pop();
		for(int i = head[t]; i != -1; i = next[i])
		{
			if(!visit[to[i]])
			{
				d[to[i]] = d[t] + 1;
				visit[to[i]] = 1;
				q.push(to[i]);
			}
		}
	}

}

int main()
{
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);

	int n; scanf("%d", &n);

	int *sp = new int[n];

	for(int i = 0 ; i < n; ++i)
	{

		int k, u, v;
		scanf("%d", &k);
		build();

		for(int j = 0; j < k-1; ++j)
		{
			scanf("%d %d", &v, &u);
			add_e(v,u);
			add_e(u,v);
		}

		bfs(1);

		//for(int j = 1; j <= k; ++j)
			//printf("%d ", d[j]);

		int max = 1;
		for(int j = 2; j <= k; ++j)
			if(d[max] < d[j])
				max = j;

		for(int j = 0; j < V; ++j)
		{
			d[j] = -1;
			visit[j] = 0;
		}

		bfs(max);

		int tmax = 1;
		for(int j = 2; j <= k; ++j)
			if(d[tmax] < d[j])
				tmax = j;

		sp[i] = d[tmax];
	}

	int ans = 0;
	for(int i = 0; i < n; ++i)
		ans += sp[i];
	printf("%d", ans);
	return 0;
}


#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <queue>
#include <utility>
#include <set>

using namespace std;

const int V = 111, E = 211, INF = 100000;

int head[V], to[E], next[E], d[V], visit[V];

int en;

void add_e(int v, int u)
{
	++en;
	to[en] = u;
	next[en] = head[v];
	head[v] = en;
}

void build()
{
	en = -1;
	for(int i = 0 ; i < V; ++i)
	{
		d[i] = INF;
		to[i] = head[i] = next[i] =  -1;
		visit[i] = 0;
	}

}

void bfs(int v)
{
	d[v] = 0;
	visit[v] = 1;

	queue <int> q;
	q.push(v);
	while(!q.empty())
	{
		int t = q.front(); q.pop();
		for(int i = head[t]; i != -1; i = next[i])
		{
			if(!visit[to[i]])
			{
				d[to[i]] = d[t] + 1;
				visit[to[i]] = 1;
				q.push(to[i]);
			}
		}
	}

}

int main()
{
	//freopen("input.txt", "rt", stdin);
	//freopen("output.txt", "wt", stdout);

	int n; scanf("%d", &n);

	int *sp = new int[n];

	for(int i = 0 ; i < n; ++i)
	{

		int k, u, v;
		scanf("%d", &k);
		build();

		for(int j = 0; j < k-1; ++j)
		{
			scanf("%d %d", &v, &u);
			add_e(v,u);
			add_e(u,v);
		}

		bfs(1);

		//for(int j = 1; j <= k; ++j)
			//printf("%d ", d[j]);

		int max = 1;
		for(int j = 2; j <= k; ++j)
			if(d[max] < d[j])
				max = j;

		for(int j = 0; j < V; ++j)
		{
			d[j] = -1;
			visit[j] = 0;
		}

		bfs(max);

		int tmax = 1;
		for(int j = 2; j <= k; ++j)
			if(d[tmax] < d[j])
				tmax = j;

		sp[i] = d[tmax];
	}

	int ans = 0;
	for(int i = 0; i < n; ++i)
		ans += sp[i];
	printf("%d", ans);
	return 0;
}


//============================================================================
// Name        : B.cpp
// Author      : bluesun
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
#define N 110

struct Edge {
    int to, next;
} _edge[N << 1];
int head[N], ec, p[N], thl;
pair<int,int> heihei;
void add_edge(int st, int ed) {
    _edge[ec].to = ed;
    _edge[ec].next = head[st];
    head[st] = ec++;
}
void dfs(int st,int len) {
    if(len>heihei.first){
        heihei.first=len;
        heihei.second=st;
    }
    for (int it = head[st]; it != -1; it = _edge[it].next) {
        int to = _edge[it].to;
        if (p[st] == to)
            continue;
        p[to] = st;
        dfs(to,len+1);
    }
}
int main() {
    setvbuf(stdout,NULL,_IONBF,0);
#ifdef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    int t;
    while (scanf(" %d",&t)==1) {
        int n,ans=0;
        while(t--)
        {
            scanf(" %d",&n);
            memset(head,-1,sizeof(head));

            ec=thl=0;
            for(int i=1;i<n;i++)
            {
                int x,y;
                scanf(" %d %d",&x,&y);
                add_edge(x,y);
                add_edge(y,x);
            }
            heihei.first=0;
            heihei.second=0;
            memset(p,-1,sizeof(p));
            dfs(1,0);
//          printf("(%d,%d)\n",heihei.first,heihei.second);
            memset(p,-1,sizeof(p));
            dfs(heihei.second,0);
            ans+=heihei.first;
//          printf("(%d,%d)\n",heihei.first,heihei.second);
//          printf("%d:%d\n",t,heihei.first);
        }
        printf("%d\n",ans);
    }
    return 0;
}


//============================================================================
// Name        : B.cpp
// Author      : bluesun
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include<stdio.h>
#include <iostream>
#include<algorithm>
#include<map>
#include<functional>
#include<string.h>
using namespace std;
#define N 110
int ans[N], dp[N];
struct Edge {
    int to, next;
} _edge[N << 1];
int head[N], ec, p[N], thl;
void add_edge(int st, int ed) {
    _edge[ec].to = ed;
    _edge[ec].next = head[st];
    head[st] = ec++;
}
void dfs(int st) {
    for (int it = head[st]; it != -1; it = _edge[it].next) {
        int to = _edge[it].to;
        if (p[st] == to)
            continue;
        p[to] = st;
        dfs(to);
        thl = max(thl, dp[to] + 1 + dp[st]);
        dp[st] = max(dp[st], dp[to] + 1);
    }
}
int main() {
//  setvbuf(stdout,NULL,_IONBF,0);
    int t;
    while (scanf(" %d",&t)==1) {
        int n,ans=0;
        while(t--)
        {

            scanf(" %d",&n);
            memset(dp,0,sizeof(dp));
            memset(head,-1,sizeof(head));
            memset(p,-1,sizeof(p));
            ec=thl=0;
            for(int i=1;i<n;i++)
            {
                int x,y;
                scanf(" %d %d",&x,&y);
                add_edge(x,y);
                add_edge(y,x);
            }
            dfs(1);
            ans+=thl;
        }
        printf("%d\n",ans);
    }
    return 0;
}


//============================================================================
// Name        : B.cpp
// Author      : bluesun
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
#define N 110

struct Edge {
    int to, next;
} _edge[N << 1];
int head[N], dp[N], ec, p[N], thl;
void add_edge(int st, int ed) {
    _edge[ec].to = ed;
    _edge[ec].next = head[st];
    head[st] = ec++;
}
void dfs(int st) {
    for (int it = head[st]; it != -1; it = _edge[it].next) {
        int to = _edge[it].to;
        if (p[st] == to)
            continue;
        p[to] = st;
        dfs(to);
        thl = max(thl, dp[to] + 1 + dp[st]);
        dp[st] = max(dp[st], dp[to] + 1);
    }
}
int main() {
    //setvbuf(stdout,NULL,_IONBF,0);
    freopen("output.txt","r",stdout);
    int t;
    while (scanf(" %d",&t)==1) {
        int n,ans=0;
        while(t--)
        {
            scanf(" %d",&n);
            memset(dp,0,sizeof(dp));
            memset(head,-1,sizeof(head));
            memset(p,-1,sizeof(p));
            ec=thl=0;
            for(int i=1;i<n;i++)
            {
                int x,y;
                scanf(" %d %d",&x,&y);
                add_edge(x,y);
                add_edge(y,x);
            }
            dfs(1);
            ans+=thl;
        }
        printf("%d\n",ans);
    }
    return 0;
}


//============================================================================
// Name        : B.cpp
// Author      : bluesun
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
#define N 110

struct Edge {
    int to, next;
} _edge[N << 1];
int head[N], dp[N], ec, p[N], thl;
void add_edge(int st, int ed) {
    _edge[ec].to = ed;
    _edge[ec].next = head[st];
    head[st] = ec++;
}
void dfs(int st) {
    for (int it = head[st]; it != -1; it = _edge[it].next) {
        int to = _edge[it].to;
        if (p[st] == to)
            continue;
        p[to] = st;
        dfs(to);
        thl = max(thl, dp[to] + 1 + dp[st]);
        dp[st] = max(dp[st], dp[to] + 1);
    }
}
int main() {
    //setvbuf(stdout,NULL,_IONBF,0);
    freopen("invoker.output-file-for-checker.txt","r",stdout);
    int t;
    while (scanf(" %d",&t)==1) {
        int n,ans=0;
        while(t--)
        {
            scanf(" %d",&n);
            memset(dp,0,sizeof(dp));
            memset(head,-1,sizeof(head));
            memset(p,-1,sizeof(p));
            ec=thl=0;
            for(int i=1;i<n;i++)
            {
                int x,y;
                scanf(" %d %d",&x,&y);
                add_edge(x,y);
                add_edge(y,x);
            }
            dfs(1);
            ans+=thl;
        }
        printf("%d\n",ans);
    }
    return 0;
}


//============================================================================
// Name        : B.cpp
// Author      : bluesun
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
#define N 110

struct Edge {
    int to, next;
} _edge[N << 1];
int head[N], dp[N], ec, p[N], thl;
void add_edge(int st, int ed) {
    _edge[ec].to = ed;
    _edge[ec].next = head[st];
    head[st] = ec++;
}
void dfs(int st) {
    for (int it = head[st]; it != -1; it = _edge[it].next) {
        int to = _edge[it].to;
        if (p[st] == to)
            continue;
        p[to] = st;
        dfs(to);
        thl = max(thl, dp[to] + 1 + dp[st]);
        dp[st] = max(dp[st], dp[to] + 1);
    }
}
int main() {
    //setvbuf(stdout,NULL,_IONBF,0);
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
//  freopen("invoker.output-file-for-checker.txt","r",stdout);
    int t;
    while (scanf(" %d",&t)==1) {
        int n,ans=0;
        while(t--)
        {
            scanf(" %d",&n);
            memset(dp,0,sizeof(dp));
            memset(head,-1,sizeof(head));
            memset(p,-1,sizeof(p));
            ec=thl=0;
            for(int i=1;i<n;i++)
            {
                int x,y;
                scanf(" %d %d",&x,&y);
                add_edge(x,y);
                add_edge(y,x);
            }
            dfs(1);
            ans+=thl;
        }
        printf("%d\n",ans);
    }
    return 0;
}


//============================================================================
// Name        : B.cpp
// Author      : bluesun
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include<stdio.h>
#include <iostream>
#include<algorithm>
#include<map>
#include<functional>
#include<string.h>
using namespace std;
#define N 110
int ans[N], dp[N];
struct Edge {
    int to, next;
} _edge[N << 1];
int head[N], ec, p[N], thl;
void add_edge(int st, int ed) {
    _edge[ec].to = ed;
    _edge[ec].next = head[st];
    head[st] = ec++;
}
void dfs(int st) {
    for (int it = head[st]; it != -1; it = _edge[it].next) {
        int to = _edge[it].to;
        if (p[st] == to)
            continue;
        p[to] = st;
        dfs(to);
        thl = max(thl, dp[to] + 1 + dp[st]);
        dp[st] = max(dp[st], dp[to] + 1);
    }
}
int main() {
//  setvbuf(stdout,NULL,_IONBF,0);
    int t;
//  while (scanf(" %d",&t)==1) {
    scanf("%d ",&t);
    {
        int n,ans=0;
        while(t--)
        {

            scanf(" %d",&n);
            memset(dp,0,sizeof(dp));
            memset(head,-1,sizeof(head));
            memset(p,-1,sizeof(p));
            ec=thl=0;
            for(int i=1;i<n;i++)
            {
                int x,y;
                scanf(" %d %d",&x,&y);
                add_edge(x,y);
                add_edge(y,x);
            }
            dfs(1);
            ans+=thl;
        }
        printf("%d\n",ans);
    }
    return 0;
}


//============================================================================
// Name        : B.cpp
// Author      : bluesun
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
#define N 110

struct Edge {
    int to, next;
} _edge[N << 1];
int head[N], ec, p[N], thl;
pair<int,int> heihei;
void add_edge(int st, int ed) {
    _edge[ec].to = ed;
    _edge[ec].next = head[st];
    head[st] = ec++;
}
void dfs(int st,int len) {
    if(len>heihei.first){
        heihei.first=len;
        heihei.second=st;
    }
    for (int it = head[st]; it != -1; it = _edge[it].next) {
        int to = _edge[it].to;
        if (p[st] == to)
            continue;
        p[to] = st;
        dfs(to,len+1);
    }
}
int main() {
    setvbuf(stdout,NULL,_IONBF,0);
#ifdef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    int t;
    while (scanf(" %d",&t)==1) {
        int n,ans=0;
        while(t--)
        {
            scanf(" %d",&n);
            memset(head,-1,sizeof(head));
            memset(p,-1,sizeof(p));
            ec=thl=0;
            for(int i=1;i<n;i++)
            {
                int x,y;
                scanf(" %d %d",&x,&y);
                add_edge(x,y);
                add_edge(y,x);
            }
            heihei.first=0;
            heihei.second=0;
            dfs(1,0);
            dfs(heihei.second,0);
            ans+=heihei.first;
        }
        printf("%d\n",ans);
    }
    return 0;
}


//============================================================================
// Name        : B.cpp
// Author      : bluesun
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
#define N 110

struct Edge {
    int to, next;
} _edge[N << 1];
int head[N], dp[N], ec, p[N], thl;
void add_edge(int st, int ed) {
    _edge[ec].to = ed;
    _edge[ec].next = head[st];
    head[st] = ec++;
}
void dfs(int st) {
    for (int it = head[st]; it != -1; it = _edge[it].next) {
        int to = _edge[it].to;
        if (p[st] == to)
            continue;
        p[to] = st;
        dfs(to);
        thl = max(thl, dp[to] + 1 + dp[st]);
        dp[st] = max(dp[st], dp[to] + 1);
    }
}
int main() {
    setvbuf(stdout,NULL,_IONBF,0);
    int t;
    while (scanf(" %d",&t)==1) {
        int n,ans=0;
        while(t--)
        {
            scanf(" %d",&n);
            memset(dp,0,sizeof(dp));
            memset(head,-1,sizeof(head));
            memset(p,-1,sizeof(p));
            ec=thl=0;
            for(int i=1;i<n;i++)
            {
                int x,y;
                scanf(" %d %d",&x,&y);
                add_edge(x,y);
                add_edge(y,x);
            }
            dfs(1);
            ans+=thl;
        }
        printf("%d\n",ans);
    }
    return 0;
}


//============================================================================
// Name        : B.cpp
// Author      : bluesun
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include<stdio.h>
#include <iostream>
#include<algorithm>
#include<map>
#include<functional>
#include<string.h>
using namespace std;
#define N 110
int ans[N], dp[N];
struct Edge {
    int to, next;
} _edge[N << 1];
int head[N], ec, p[N], thl;
void add_edge(int st, int ed) {
    _edge[ec].to = ed;
    _edge[ec].next = head[st];
    head[st] = ec++;
}
void dfs(int st) {
    for (int it = head[st]; it != -1; it = _edge[it].next) {
        int to = _edge[it].to;
        if (p[st] == to)
            continue;
        p[to] = st;
        dfs(to);
        thl = max(thl, dp[to] + 1 + dp[st]);
        dp[st] = max(dp[st], dp[to] + 1);
    }
}
int main() {
    setvbuf(stdout,NULL,_IONBF,0);
    int t;
    while (scanf(" %d",&t)==1) {
        int n,ans=0;
        while(t--)
        {

            scanf(" %d",&n);
            memset(dp,0,sizeof(dp));
            memset(head,-1,sizeof(head));
            memset(p,-1,sizeof(p));
            ec=thl=0;
            for(int i=1;i<n;i++)
            {
                int x,y;
                scanf(" %d %d",&x,&y);
                add_edge(x,y);
                add_edge(y,x);
            }
            dfs(1);
            ans+=thl;
        }
        printf("%d\n",ans);
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<map>
#include<string>
#include<queue>
#include<vector>
#include<list>
#include<bitset>
//#pragma comment(linker,"/STACK:1024000000,1024000000")
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
vector<int> G[105];
int n,m;
int dis[105];
int bfs(int u)
{
    queue<int> que;
    que.push(u);
    dis[u]=0;
    int Max=0,Maxi=1;
    while(!que.empty())
    {
        int f=que.front();que.pop();
        if(dis[f]>Max) Maxi=f;
        for(int i=0;i<G[f].size();i++)
        {
            int to=G[f][i];
            if(dis[to]==-1)
                que.push(to),dis[to]=dis[f]+1;
        }
    }
    return Maxi;
}
int main()
{
    while(~scanf("%d",&n))
    {
        int ans=0;
        for(int i=1;i<=n;i++)
        {
            for(int j=0;j<105;j++) G[j].clear();

            scanf("%d",&m);
            for(int j=1;j<m;j++)
            {
                int u,v;
                scanf("%d%d",&u,&v);
                G[u].push_back(v);
                G[v].push_back(u);
            }
            memset(dis,-1,sizeof dis);
            int p=bfs(1);
            memset(dis,-1,sizeof dis);
            int q=bfs(p);
            ans+=dis[q];
        }
        printf("%d\n",ans);
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<map>
#include<string>
#include<queue>
#include<vector>
#include<list>
#include<bitset>
//#pragma comment(linker,"/STACK:1024000000,1024000000")
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
vector<int> G[105];
int n,m;
int dis[105];
int bfs(int u)
{
    queue<int> que;
    que.push(u);
    dis[u]=0;
    int Max=0,Maxi=1;
    while(!que.empty())
    {
        int f=que.front();que.pop();
        if(dis[f]>Max) Maxi=f;
        for(int i=0;i<G[f].size();i++)
        {
            int to=G[f][i];
            if(dis[to]==-1)
                que.push(to),dis[to]=dis[f]+1;
        }
    }
    return Maxi;
}
int main()
{scanf("%d",&n);
//    while(~)
    {
        int ans=0;
        for(int i=1;i<=n;i++)
        {
            for(int j=0;j<105;j++) G[j].clear();

            scanf("%d",&m);
            for(int j=1;j<m;j++)
            {
                int u,v;
                scanf("%d%d",&u,&v);
                G[u].push_back(v);
                G[v].push_back(u);
            }
            memset(dis,-1,sizeof dis);
            int p=bfs(1);
            memset(dis,-1,sizeof dis);
            int q=bfs(p);
            ans+=dis[q];
        }
        printf("%d\n",ans);
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<map>
#include<string>
#include<queue>
#include<vector>
#include<list>
#include<bitset>
//#pragma comment(linker,"/STACK:1024000000,1024000000")
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
vector<int> G[105];
int n,m;
int dis[105];
int bfs(int u)
{
    queue<int> que;
    que.push(u);
    dis[u]=0;
    int Max=0,Maxi=1;
    while(!que.empty())
    {
        int f=que.front();que.pop();
        if(dis[f]>Max) Maxi=f;
        for(int i=0;i<G[f].size();i++)
        {
            int to=G[f][i];
            if(dis[to]==-1)
                que.push(to),dis[to]=dis[f]+1;
        }
    }
    return Maxi;
}
int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    while(~scanf("%d",&n))
    {
        int ans=0;
        for(int i=1;i<=n;i++)
        {
            for(int j=0;j<105;j++) G[j].clear();

            scanf("%d",&m);
            for(int j=1;j<m;j++)
            {
                int u,v;
                scanf("%d%d",&u,&v);
                G[u].push_back(v);
                G[v].push_back(u);
            }
            memset(dis,-1,sizeof dis);
            int p=bfs(1);
            memset(dis,-1,sizeof dis);
            int q=bfs(p);
            ans+=dis[q];
        }
        printf("%d\n",ans);
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <fstream>

using namespace std;

ifstream fin ("input.txt");
ofstream fout ("output.txt");

#define cin fin
#define cout fout

const int MAXN = 100+10;
int N, M, ans, index, sum, u, v;
bool mark[MAXN];

vector <int> g[MAXN];

void dfs(int u, int level)
{
	mark[u] = 1;
	if (level > ans)
	{
		ans = level;
		index = u;
	}
	for (int i = 0 ; i < g[u].size() ; i++)
		if (!mark[g[u][i]])
			dfs(g[u][i], level+1);
}

int main()
{
	cin >> N;
	for (int i = 1 ; i <= N ; i++)
	{
		for (int i = 0 ; i < MAXN ; i++)
			g[i].resize(0);
		cin >> M;
		for (int i = 0 ; i < M-1 ; i++)
		{
			cin >> u >> v;
			g[u].push_back(v);
			g[v].push_back(u);
		}
		dfs(1, 0);
		ans = 0;
		for (int i = 0 ; i < MAXN ; i++)
			mark[i] = 0;
		dfs(index, 0);
		sum += ans;
	}
	cout << sum << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <fstream>

using namespace std;

ifstream fin ("input.txt");
ofstream fout ("output.txt");

#define cin fin
#define cout fout

const int MAXN = 200;
int N, M, ans, index, sum, u, v;
bool mark[MAXN];

vector <int> g[MAXN];

void dfs(int u, int level)
{
	mark[u] = 1;
	if (level > ans)
	{
		ans = level;
		index = u;
	}
	for (int i = 0 ; i < g[u].size() ; i++)
		if (!mark[g[u][i]])
			dfs(g[u][i], level+1);
}

int main()
{
	cin >> N;
	for (int i = 1 ; i <= N ; i++)
	{
		for (int i = 0 ; i < MAXN ; i++)
			g[i].resize(0);
		cin >> M;
		for (int i = 0 ; i < M-1 ; i++)
		{
			cin >> u >> v;
			g[u].push_back(v);
			g[v].push_back(u);
		}
		ans = 0;
		dfs(1, 0);
		ans = 0;
		for (int i = 0 ; i < MAXN ; i++)
			mark[i] = 0;
		dfs(index, 0);
		sum += ans;
	}
	cout << sum << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <fstream>

using namespace std;

ifstream fin ("input.txt");
ofstream fout ("output.txt");

#define cin fin
#define cout fout

const int MAXN = 200;
int N, M, ans, index, sum, u, v;
bool mark[MAXN];

vector <int> g[MAXN];

void dfs(int u, int level)
{
	mark[u] = 1;
	if (level > ans)
	{
		ans = level;
		index = u;
	}
	for (int i = 0 ; i < g[u].size() ; i++)
		if (!mark[g[u][i]])
			dfs(g[u][i], level+1);
}

int main()
{
	cin >> N;
	for (int i = 1 ; i <= N ; i++)
	{
		for (int i = 0 ; i < MAXN ; i++)
			g[i].resize(0);
		cin >> M;
		for (int i = 0 ; i < M-1 ; i++)
		{
			cin >> u >> v;
			g[u].push_back(v);
			g[v].push_back(u);
		}
		for (int i = 0 ; i < MAXN ; i++)
			mark[i] = 0;
		ans = 0;
		dfs(1, 0);
		ans = 0;
		for (int i = 0 ; i < MAXN ; i++)
			mark[i] = 0;
		dfs(index, 0);
		sum += ans;
	}
	cout << sum << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <fstream>

using namespace std;

ifstream fin ("input.txt");
ofstream fout ("output.txt");

#define cin fin
#define cout fout

const int MAXN = 200;
int N, M, ans, index, sum, u, v;
bool mark[MAXN];

vector <int> g[MAXN];

void dfs(int u, int level)
{
	mark[u] = 1;
	if (level > ans)
	{
		ans = level;
		index = u;
	}
	for (int i = 0 ; i < g[u].size() ; i++)
		if (!mark[g[u][i]])
			dfs(g[u][i], level+1);
}

int main()
{
	cin >> N;
	for (int i = 1 ; i <= N ; i++)
	{
		for (int i = 0 ; i < MAXN ; i++)
			g[i].resize(0);
		cin >> M;
		for (int i = 0 ; i < M-1 ; i++)
		{
			cin >> u >> v;
			g[u].push_back(v);
			g[v].push_back(u);
		}
		dfs(1, 0);
		ans = 0;
		for (int i = 0 ; i < MAXN ; i++)
			mark[i] = 0;
		dfs(index, 0);
		sum += ans;
	}
	cout << sum << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n,c;
vector<int> v[109];
void dfs(int id,int par,int d,int* t)
{
	for(int i=0;i<v[id].size();i++)
	{
		if(v[id][i]==par)continue;
		dfs(v[id][i],id,d+1,t);
	}
	*t=max(*t,d);
}
int main()
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin>>n;
	while(n--)
	{
		int m,x,y;
		cin>>m;
		for(int i=1;i<=m;i++)
			v[i].clear();
		for(int i=1;i<m;i++)
		{
			cin>>x>>y;
			v[x].push_back(y);
			v[y].push_back(x);
		}
		int t=0;
		for(int i=1;i<=m;i++)
			dfs(1,0,0,&t);
		c+=t;
	}
	cout<<c;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n,c;
vector<int> v[109];
void dfs(int id,int par,int d,int* t)
{
	for(int i=0;i<v[id].size();i++)
	{
		if(v[id][i]==par)continue;
		dfs(v[id][i],id,d+1,t);
	}
	*t=max(*t,d);
}
int main()
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin>>n;
	while(n--)
	{
		int m,x,y;
		cin>>m;
		for(int i=1;i<=m;i++)
			v[i].clear();
		for(int i=1;i<m;i++)
		{
			cin>>x>>y;
			v[x].push_back(y);
			v[y].push_back(x);
		}
		int t=0;
		for(int i=1;i<=m;i++)
			dfs(i,0,0,&t);
		c+=t;
	}
	cout<<c;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n,c;
vector<int> v[109];
void dfs(int id,int par,int d,int* t)
{
	for(int i=0;i<v[id].size();i++)
	{
		if(v[id][i]==par)continue;
		dfs(v[id][i],id,d+1,t);
	}
	*t=max(*t,d);
}
int main()
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdin);
	cin>>n;
	while(n--)
	{
		int m,x,y;
		cin>>m;
		for(int i=1;i<=m;i++)
			v[i].clear();
		for(int i=1;i<m;i++)
		{
			cin>>x>>y;
			v[x].push_back(y);
			v[y].push_back(x);
		}
		int t=0;
		for(int i=1;i<=m;i++)
			dfs(1,0,0,&t);
		c+=t;
	}
	cout<<c;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n,c;
vector<int> v[109];
void dfs(int id,int par,int d,int* t)
{
	for(int i=0;i<v[id].size();i++)
	{
		if(v[id][i]==par)continue;
		dfs(v[id][i],id,d+1,t);
	}
	*t=max(*t,d);
}
int main()
{
	cin>>n;
	while(n--)
	{
		int m,x,y;
		cin>>m;
		for(int i=1;i<=m;i++)
			v[i].clear();
		for(int i=1;i<m;i++)
		{
			cin>>x>>y;
			v[x].push_back(y);
			v[y].push_back(x);
		}
		int t=0;
		for(int i=1;i<=m;i++)
			dfs(1,0,0,&t);
		c+=t;
	}
	cout<<c;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 1e2 + 5;
int gdists[MAX_N];

void dfs(int v, int p, int dist[], vector<int> g[], vector<bool> visited, int graph){
	visited[v] = true;
    dist[v] = p != -1 ? dist[p] + 1 : 1;
	for(int i = 0; i < g[v].size(); i++){
		if(!visited[g[v][i]]){
            gdists[graph] = max(gdists[graph], dist[v]);
			dfs(g[v][i], v, dist, g, visited, graph);
		}
	}
}
int main(){
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
	 int beads;
	 cin >> beads;
	 long res = 0;
	 for(int i = 0; i < MAX_N; i++){
	 	gdists[i] = 0;
	 }
	 for(int tt = 0; tt < beads; tt++){
		int cc;
		cin >> cc;
		vector<int> g[MAX_N];
		vector<bool> visited(MAX_N, false);
		int dist[MAX_N];
		for(int i = 0; i < cc; i++){
			dist[i] = 0;
		}
		int b = 1;
		for(int c = 0; c < cc - 1; c++){
			int x, y;
			cin >> x >> y;
			b = x;
			g[x].push_back(y);
			g[y].push_back(x);
		}
		for(int i = 1; i <= cc; i++){
		  if(!visited[i]){
		  	dfs(i, -1, dist, g, visited,tt);
		  }
	   }
		//printf("Maximum path in graph %d is %d\n", tt + 1,gdists[tt]);
		res += gdists[tt];
	 }
	cout << /*"Case #" << j << ": " << */res << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 1e2 + 5;
int gdists[MAX_N];

void dfs(int v, int p, int dist[], vector<int> g[], vector<bool> visited, int graph){
	visited[v] = true;
    dist[v] = p != -1 ? dist[p] + 1 : 1;
	for(int i = 0; i < g[v].size(); i++){
		if(!visited[g[v][i]]){
            gdists[graph] = max(gdists[graph], dist[v]);
			dfs(g[v][i], v, dist, g, visited, graph);
		}
	}
}
int main(){
	freopen("input.txt", "rt", stdin);
	freopen("input.txt", "wt", stdout);
	 int beads;
	 cin >> beads;
	 long res = 0;
	 for(int i = 0; i < MAX_N; i++){
	 	gdists[i] = 0;
	 }
	 for(int tt = 0; tt < beads; tt++){
		int cc;
		cin >> cc;
		vector<int> g[MAX_N];
		vector<bool> visited(MAX_N, false);
		int dist[MAX_N];
		for(int i = 0; i < cc; i++){
			dist[i] = 0;
		}
		int b = 1;
		for(int c = 0; c < cc - 1; c++){
			int x, y;
			cin >> x >> y;
			b = x;
			g[x].push_back(y);
			g[y].push_back(x);
		}
		for(int i = 1; i <= cc; i++){
		  if(!visited[i]){
		  	dfs(i, -1, dist, g, visited,tt);
		  }
	   }
		//printf("Maximum path in graph %d is %d\n", tt + 1,gdists[tt]);
		res += gdists[tt];
	 }
	cout << /*"Case #" << j << ": " << */res << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 1e2 + 5;
int gdists[MAX_N];

void dfs(int v, int p, int dist[], vector<int> g[], vector<bool> visited, int graph){
	visited[v] = true;
    dist[v] = p != -1 ? dist[p] + 1 : 1;
	for(int i = 0; i < g[v].size(); i++){
		if(!visited[g[v][i]]){
            gdists[graph] = max(gdists[graph], dist[v]);
			dfs(g[v][i], v, dist, g, visited, graph);
		}
	}
}
int main(){
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
	 int beads;
	 scanf("%d",&beads);
	 int res = 0;
	 for(int i = 0; i < MAX_N; i++){
	 	gdists[i] = 0;
	 }
	 for(int tt = 0; tt < beads; tt++){
		int cc;
		scanf("%d",&cc);
		vector<int> g[MAX_N];
		vector<bool> visited(MAX_N, false);
		int dist[MAX_N];
		for(int i = 0; i < cc; i++){
			dist[i] = 0;
		}
		int b = 1;
		for(int c = 0; c < cc - 1; c++){
			int x, y;
			scanf("%d%d", &x, &y);
			b = x;
			g[x].push_back(y);
			g[y].push_back(x);
		}
		for(int i = 1; i <= cc; i++){
		  if(!visited[i]){
		  	dfs(i, -1, dist, g, visited,tt);
		  }
	   }
		//printf("Maximum path in graph %d is %d\n", tt + 1,gdists[tt]);
		res += gdists[tt];
	 }
	printf("%d", res);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 1e2 + 5;
int gdists[MAX_N];

void dfs(int v, int p, int dist[], vector<int> g[], vector<bool> visited, int graph){
	visited[v] = true;
    dist[v] = p != -1 ? dist[p] + 1 : 1;
	for(int i = 0; i < g[v].size(); i++){
		if(!visited[g[v][i]]){
            gdists[graph] = max(gdists[graph], dist[v]);
			dfs(g[v][i], v, dist, g, visited, graph);
		}
	}
}
int main(){
	 int beads;
	 cin >> beads;
	 long res = 0;
	 for(int i = 0; i < MAX_N; i++){
	 	gdists[i] = 0;
	 }
	 for(int tt = 0; tt < beads; tt++){
		int cc;
		cin >> cc;
		vector<int> g[MAX_N];
		vector<bool> visited(MAX_N, false);
		int dist[MAX_N];
		for(int i = 0; i < cc; i++){
			dist[i] = 0;
		}
		int b = 1;
		for(int c = 0; c < cc - 1; c++){
			int x, y;
			cin >> x >> y;
			b = x;
			g[x].push_back(y);
			g[y].push_back(x);
		}
		for(int i = 1; i <= cc; i++){
		  if(!visited[i]){
		  	dfs(i, -1, dist, g, visited,tt);
		  }
	   }
		//printf("Maximum path in graph %d is %d\n", tt + 1,gdists[tt]);
		res += gdists[tt];
	 }
	cout << /*"Case #" << j << ": " << */res << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int graph[200][200],n,k,l,i,j,a,b,t,m,s,h[200];
void f(int j,int p)
{
	if(h[j])return ;
	h[j]=1;
	if(p>m)m=p;
	for(int i=1;i<=k;i++)
	{
		if(graph[j][i])
			f(i,p+1);
	}
	h[j]=0;
}
int main()
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin>>n;
	for(i=0;i<n;i++)
	{
		for(j=0;j<110;j++)
			for(l=0;l<110;l++)graph[j][l]=0;
		cin>>k;
		m=0;
		for(j=1;j<k;j++)
		{
			cin>>a>>b;
			graph[a][b]=graph[b][a]=1;
		}
		for(j=1;j<=k;j++)
			f(j,0);
		t+=m;
	}
	cout<<t<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int graph[200][200],n,k,l,i,j,a,b,t,m,s,h[200];
void f(int j,int p)
{
	if(h[j]) return;
	h[j]=1;
	if(p>m)m=p;
	for(int i=1;i<=k;i++)
	{
		if(graph[j][i])
			f(i,p+1);
	}
	h[j]=0;
}
int main()
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin>>n;
	for(i=0;i<n;i++)
	{
		for(j=0;j<110;j++)
			for(l=0;l<110;l++)graph[j][l]=0;
		cin>>k;
		for(j=1;j<k;j++)
		{
			cin>>a>>b;
			graph[a][b]=graph[b][a]=1;
		}
		for(j=1;j<=k;j++)
		{
			f(j,0);
		}
//		cout<<m<<endl;
		t+=m;
	}
	cout<<t<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int graph[200][200],n,k,l,i,j,a,b,t,m,s,h[200];
void f(int j,int p)
{
	if(h[j]) return;
	h[j]=1;
	if(p>m)m=p;
	for(int i=1;i<=k;i++)
	{
		if(graph[j][i])
			f(i,p+1);
	}
	h[j]=0;
}
int main()
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin>>n;
	for(i=0;i<n;i++)
	{
		for(j=0;j<110;j++)
			for(l=0;l<110;l++)graph[j][l]=0;
		cin>>k;
		for(j=1;j<k;j++)
		{
			cin>>a>>b;
			graph[a][b]=graph[b][a]=1;
		}
		for(j=1;j<=k;j++)
		{
			f(j,0);
		}
		cout<<m<<endl;
		t+=m;
	}
	cout<<t<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int graph[200][200],n,k,l,i,j,a,b,t,m,s,h[200];
void f(int j,int p)
{
	if(h[j]) return;
	h[j]=1;
	if(p>m)m=p;
	for(int i=1;i<=k;i++)
	{
		if(graph[j][i])
			f(i,p+1);
	}
	h[j]=0;
}
int main()
{
	cin>>n;
	for(i=0;i<n;i++)
	{
		for(j=0;j<110;j++)
			for(l=0;l<110;l++)graph[j][l]=0;
		cin>>k;
		for(j=1;j<k;j++)
		{
			cin>>a>>b;
			graph[a][b]=graph[b][a]=1;
		}
		for(j=1;j<=k;j++)
		{
			m=0;f(j,0);
		}
		t+=m;
	}
	cout<<t<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int graph[200][200],n,k,l,i,j,a,b,t,m,s,h[200];
void f(int j,int p)
{
	if(h[j]) return;
	h[j]=1;
	if(p>m)m=p;
	for(int i=1;i<=k;i++)
	{
		if(graph[j][i])
			f(i,p+1);
	}
	h[j]=0;
}
int main()
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin>>n;
	for(i=0;i<n;i++)
	{
		for(j=0;j<110;j++)
			for(l=0;l<110;l++)graph[j][l]=0;
		cin>>k;
		for(j=1;j<k;j++)
		{
			cin>>a>>b;
			graph[a][b]=graph[b][a]=1;
		}
		for(j=1;j<=k;j++)
		{
			m=0;f(j,0);
		}
		t+=m;
	}
	cout<<t<<endl;
}


#include<iostream>
#include<fstream>
#include<stdio.h>
#include<vector>
using namespace std;

vector<int> degree;

int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
    int n,i,ni,j,x,y,ans = 0,temp = 0;
    scanf("%d",&n);
    for(i = 1 ; i <= n ; i++){
        temp = 1;
        scanf("%d",&ni);
        degree.resize(ni + 1);
        for(j = 1 ; j <= ni ; j++)
            degree[j] = 0;
        for(j = 1 ; j <= ni-1 ; j++){
            scanf("%d %d",&x,&y);
            degree[x]++;degree[y]++;
            if(degree[x] == 2 || degree[y] == 2)
                temp++;
        }
        ans += temp;
    }

    printf("%d",ans);

    return 0;
}


#include<iostream>
#include<fstream>
#include<stdio.h>
#include<vector>
using namespace std;

vector<int> degree;

int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
    int n,i,ni,j,x,y,ans = 0,temp = 0;
    scanf("%d",&n);
    for(i = 1 ; i <= n ; i++){
        temp = 1;
        scanf("%d",&ni);
        degree.resize(ni + 1);
        for(j = 1 ; j <= ni ; j++)
            degree[j] = 0;
        for(j = 1 ; j <= ni-1 ; j++){
            scanf("%d %d",&x,&y);
            degree[x]++;degree[y]++;
            if(degree[x] == 2 || degree[y] == 2)
                temp++;
        }
        ans += temp;
    }

    printf("%d",ans);

return 0;
}


RY9AZ-3ZSXX-JR02B-1U5IO -use this one
D60G8-Y85O8-B5YZV-U0PB3
AT6H7-TDK7X-YMB5W-QA809
DUJ7M-BBNR6-CML6I-9HVEY
U6JY7-O1C4Z-OPPJR-0JXHH
9QZWY-4AFHB-IPJ4T-RBJSE
D87W5-CKD63-RGUNI-X68EG

RLDGN-OV9WU-5W589-6VZH1
HUDWE-UO689-6D27B-YM28M
UK3DV-E0MNW-MLQYX-GENA1
398ND-QNAGY-CMMZU-ZPI39
GZLJY-X50S3-0S20D-NFRF9
W3J5U-8U66N-D0B9M-54SLM
EC0Q6-QN7UH-5S3JB-YZMEK
UVQW0-X54FE-QW35Q-SNZF5
FJJTJ-J0FLF-QCVBK-A287M


#include <bits/stdc++.h>
using namespace std;

#define lli long long int
#define ii pair<int,int>
#define mod 1000000007
#define inf 999999999
#define lim 100010

using namespace std;

int t,n;
vector<int> g[101];
int ht[101],vis[101],ans[101];

void dfs(int u) {
	vis[u]=1;
	ht[u]=0;
	ans[u]=0;

	int val=0;

	for(int i=0;i<g[u].size();i++) {
		int v=g[u][i];
		if(vis[v]==0) {
			dfs(v);
			ans[u]=max(ans[u],ans[v]);
			ans[u]=max(ans[u],ht[v]+ht[u]+1);
			ht[u]=max(ht[u],ht[v]+1);
		}
	}
}

int main(){
	// cin.sync_with_stdio(false);

	cin>>t;

	int val=0;
	while(t--) {
		printf("what\n");
		cin>>n;

		for(int i=1;i<=n;i++)
			g[i].clear();

		for(int i=1;i<n;i++) {
			int a,b;
			cin>>a>>b;
			g[a].push_back(b);
			g[b].push_back(a);
		}

		memset(vis,0,sizeof vis);

		dfs(1);
		val+=ans[1];

	}

	cout<<val<<endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define lli long long int
#define ii pair<int,int>
#define mod 1000000007
#define inf 999999999
#define lim 100010

using namespace std;

int t,n;
vector<int> g[101];
int ht[101],vis[101],ans[101];

void dfs(int u) {
	vis[u]=1;
	ht[u]=0;
	ans[u]=0;

	int val=0;

	for(int i=0;i<g[u].size();i++) {
		int v=g[u][i];
		if(vis[v]==0) {
			dfs(v);
			ans[u]=max(ans[u],ans[v]);
			ans[u]=max(ans[u],ht[v]+ht[u]+1);
			ht[u]=max(ht[u],ht[v]+1);
		}
	}
}

int main(){
	// cin.sync_with_stdio(false);
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);

	cin>>t;

	int val=0;
	while(t--) {
		cin>>n;

		for(int i=1;i<=n;i++)
			g[i].clear();

		for(int i=1;i<n;i++) {
			int a,b;
			cin>>a>>b;
			g[a].push_back(b);
			g[b].push_back(a);
		}

		memset(vis,0,sizeof vis);

		dfs(1);
		val+=ans[1];

	}

	cout<<val<<endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define lli long long int
#define ii pair<int,int>
#define mod 1000000007
#define inf 999999999
#define lim 100010

using namespace std;

int t,n;
vector<int> g[101];
int ht[101],vis[101],ans[101];

void dfs(int u) {
	vis[u]=1;
	ht[u]=0;
	ans[u]=0;

	int val=0;

	for(int i=0;i<g[u].size();i++) {
		int v=g[u][i];
		if(vis[v]==0) {
			dfs(v);
			ans[u]=max(ans[u],ans[v]);
			ans[u]=max(ans[u],ht[v]+ht[u]+1);
			ht[u]=max(ht[u],ht[v]+1);
		}
	}
}

int main(){
	// cin.sync_with_stdio(false);

	cin>>t;

	int ans1=0;
	while(t--) {
		cin>>n;

		for(int i=1;i<=n;i++)
			g[i].clear();

		for(int i=1;i<n;i++) {
			int a,b;
			cin>>a>>b;
			g[a].push_back(b);
			g[b].push_back(a);
		}

		memset(vis,0,sizeof vis);

		dfs(1);
		ans1+=ans[1];
	}

	cout<<ans1<<endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define lli long long int
#define ii pair<int,int>
#define mod 1000000007
#define inf 999999999
#define lim 100010

using namespace std;

int t,n;
vector<int> g[101];
int ht[101],vis[101],ans[101];

void dfs(int u) {
	vis[u]=1;
	ht[u]=0;
	ans[u]=0;

	int val=0;

	for(int i=0;i<g[u].size();i++) {
		int v=g[u][i];
		if(vis[v]==0) {
			dfs(v);
			ans[u]=max(ans[u],ans[v]);
			ans[u]=max(ans[u],ht[v]+ht[u]+1);
			ht[u]=max(ht[u],ht[v]+1);
		}
	}
}

int main(){
	// cin.sync_with_stdio(false);

	cin>>t;

	int val=0;
	while(t--) {
		cin>>n;

		for(int i=1;i<=n;i++)
			g[i].clear();

		for(int i=1;i<n;i++) {
			int a,b;
			cin>>a>>b;
			g[a].push_back(b);
			g[b].push_back(a);
		}

		memset(vis,0,sizeof vis);

		dfs(1);
		val+=ans[1];
	}

	cout<<val<<endl;

	return 0;
}


/**
 * Author: Sergey Kopeliovich (Burunduk30@gmail.com)
 */

/* Template */

#include <cstdarg>
#include <ctime>
#include <cmath>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>

#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <iostream>
#include <functional>
#include <map>
#include <set>
#include <fstream>
#include <queue>

using namespace std;

#ifdef _WIN32
#  define I64 "%I64d"
#else
#  define I64 "%Ld"
#endif

#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define fornd(i, n) for (int i = (int)(n) - 1; i >= 0; i--)
#define forab(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)
#define forabd(i, a, b) for (int i = (int)(b); i >= (int)(a); i--)
#define forit(i, a) for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define zero(a) memset(a, 0, sizeof(a))
#define fill(a, x) memset(a, x, sizeof(a))
#define pb push_back
#define mp make_pair

#define EOL(i, n) " \n"[i == (n) - 1]
#define LEN(a) (int)(sizeof(a) / sizeof(a[0]))
#define IS(a, i) (((a) >> (i)) & 1)
#define LAST(a) a[sz(a) - 1]

typedef unsigned int uint;
typedef double dbl;
typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef pair <int, int> pii;
typedef unsigned char byte;

template <class T> T inline sqr(T x) { return x * x; }
template <class T> inline void relaxMin( T &a, T b ) { a = min(a, b); }
template <class T> inline void relaxMax( T &a, T b ) { a = max(a, b); }

string str( int i ) { char s[100]; sprintf(s, "%d", i); return string(s); }

template <class T> inline T sign( T x ) { return x > 0 ? 1 : (x < 0 ? -1 : 0); }
template <class T> inline T myAbs( T a ) { return a > 0 ? a : -a; }

#define DEBUG 1
void err( const char *fmt, ... )
{
  #if DEBUG
  va_list list;
  va_start(list, fmt);
  vfprintf(stderr, fmt, list);
  #endif
}

/* The main part */

const int maxn = 1010;

int sum, n, k, c[maxn][maxn];

int main()
{
  assert(freopen("input.txt", "r", stdin));
  assert(freopen("output.txt", "w", stdout));

  scanf("%d", &n);
  forn(s, n)
  {
    scanf("%d", &k);
    forn(i, k)
      forn(j, k)
        c[i][j] = (int)1e9;
    forn(i, k - 1)
    {
      int a, b;
      scanf("%d%d", &a, &b), a--, b--;
      c[a][b] = c[b][a] = 1;
    }
    forn(s, k)
      forn(t, k)
        forn(i, k)
          forn(j, k)
            relaxMin(c[i][j], c[i][t] + c[t][j]);

    int ma = 0;
    forn(i, k)
      forn(j, k)
        relaxMax(ma, c[i][j]);
    sum += ma;
  }
  printf("%d\n", sum);
  return 0;
}


/**
 * Author: Sergey Kopeliovich (Burunduk30@gmail.com)
 */

/* Template */

#include <cstdarg>
#include <ctime>
#include <cmath>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>

#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <iostream>
#include <functional>
#include <map>
#include <set>
#include <fstream>
#include <queue>

using namespace std;

#ifdef _WIN32
#  define I64 "%I64d"
#else
#  define I64 "%Ld"
#endif

#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define fornd(i, n) for (int i = (int)(n) - 1; i >= 0; i--)
#define forab(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)
#define forabd(i, a, b) for (int i = (int)(b); i >= (int)(a); i--)
#define forit(i, a) for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define zero(a) memset(a, 0, sizeof(a))
#define fill(a, x) memset(a, x, sizeof(a))
#define pb push_back
#define mp make_pair

#define EOL(i, n) " \n"[i == (n) - 1]
#define LEN(a) (int)(sizeof(a) / sizeof(a[0]))
#define IS(a, i) (((a) >> (i)) & 1)
#define LAST(a) a[sz(a) - 1]

typedef unsigned int uint;
typedef double dbl;
typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef pair <int, int> pii;
typedef unsigned char byte;

template <class T> T inline sqr(T x) { return x * x; }
template <class T> inline void relaxMin( T &a, T b ) { a = min(a, b); }
template <class T> inline void relaxMax( T &a, T b ) { a = max(a, b); }

string str( int i ) { char s[100]; sprintf(s, "%d", i); return string(s); }

template <class T> inline T sign( T x ) { return x > 0 ? 1 : (x < 0 ? -1 : 0); }
template <class T> inline T myAbs( T a ) { return a > 0 ? a : -a; }

#define DEBUG 1
void err( const char *fmt, ... )
{
  #if DEBUG
  va_list list;
  va_start(list, fmt);
  vfprintf(stderr, fmt, list);
  #endif
}

/* The main part */

const int maxn = 1010;

int sum, n, k, c[maxn][maxn];

int main()
{
  assert(freopen("input.txt", "r", stdin));
  assert(freopen("output.txt", "w", stdout));

  scanf("%d", &n);
  forn(s, n)
  {
    scanf("%d", &k);
    forn(i, k)
      forn(j, k)
        c[i][j] = (int)1e9;
    forn(i, k)
      c[i][i] = 0;
    forn(i, k - 1)
    {
      int a, b;
      scanf("%d%d", &a, &b), a--, b--;
      c[a][b] = c[b][a] = 1;
    }
    forn(t, k)
      forn(i, k)
        forn(j, k)
          relaxMin(c[i][j], c[i][t] + c[t][j]);

    int ma = 0;
    forn(i, k)
      forn(j, k)
        relaxMax(ma, c[i][j]);
    sum += ma;
  }
  printf("%d\n", sum);
  return 0;
}


/**
 * Author: Sergey Kopeliovich (Burunduk30@gmail.com)
 */

/* Template */

#include <cstdarg>
#include <ctime>
#include <cmath>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>

#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <iostream>
#include <functional>
#include <map>
#include <set>
#include <fstream>
#include <queue>

using namespace std;

#ifdef _WIN32
#  define I64 "%I64d"
#else
#  define I64 "%Ld"
#endif

#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define fornd(i, n) for (int i = (int)(n) - 1; i >= 0; i--)
#define forab(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)
#define forabd(i, a, b) for (int i = (int)(b); i >= (int)(a); i--)
#define forit(i, a) for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define zero(a) memset(a, 0, sizeof(a))
#define fill(a, x) memset(a, x, sizeof(a))
#define pb push_back
#define mp make_pair

#define EOL(i, n) " \n"[i == (n) - 1]
#define LEN(a) (int)(sizeof(a) / sizeof(a[0]))
#define IS(a, i) (((a) >> (i)) & 1)
#define LAST(a) a[sz(a) - 1]

typedef unsigned int uint;
typedef double dbl;
typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef pair <int, int> pii;
typedef unsigned char byte;

template <class T> T inline sqr(T x) { return x * x; }
template <class T> inline void relaxMin( T &a, T b ) { a = min(a, b); }
template <class T> inline void relaxMax( T &a, T b ) { a = max(a, b); }

string str( int i ) { char s[100]; sprintf(s, "%d", i); return string(s); }

template <class T> inline T sign( T x ) { return x > 0 ? 1 : (x < 0 ? -1 : 0); }
template <class T> inline T myAbs( T a ) { return a > 0 ? a : -a; }

#define DEBUG 1
void err( const char *fmt, ... )
{
  #if DEBUG
  va_list list;
  va_start(list, fmt);
  vfprintf(stderr, fmt, list);
  #endif
}

/* The main part */

const int maxn = 1010;

int n, k, a[maxn], c[maxn][maxn];
int main()
{
  assert(freopen("input.txt", "r", stdin));
  assert(freopen("output.txt", "w", stdout));

  scanf("%d", &n);
  forn(s, n)
  {
    scanf("%d", &k);
    forn(i, k)
      forn(j, k)
        c[i][j] = k;
    forn(i, k - 1)
    {
      int a, b;
      scanf("%d%d", &a, &b), a--, b--;
      c[a][b] = c[b][a] = 1;
    }
    forn(t, k)
      forn(i, k)
        forn(j, k)
          relaxMin(c[i][j], c[i][t] + c[t][j]);

    int ma = 0;
    forn(i, k)
      forn(j, k)
        relaxMax(ma, c[i][j]);
    a[s] = ma;
  }

  int sum = 0;
  forn(i, n)
    sum += a[i];
  printf("%d\n", sum);
  return 0;
}


/**
 * Author: Sergey Kopeliovich (Burunduk30@gmail.com)
 */

/* Template */

#include <cstdarg>
#include <ctime>
#include <cmath>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>

#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <iostream>
#include <functional>
#include <map>
#include <set>
#include <fstream>
#include <queue>

using namespace std;

#ifdef _WIN32
#  define I64 "%I64d"
#else
#  define I64 "%Ld"
#endif

#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define fornd(i, n) for (int i = (int)(n) - 1; i >= 0; i--)
#define forab(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)
#define forabd(i, a, b) for (int i = (int)(b); i >= (int)(a); i--)
#define forit(i, a) for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define zero(a) memset(a, 0, sizeof(a))
#define fill(a, x) memset(a, x, sizeof(a))
#define pb push_back
#define mp make_pair

#define EOL(i, n) " \n"[i == (n) - 1]
#define LEN(a) (int)(sizeof(a) / sizeof(a[0]))
#define IS(a, i) (((a) >> (i)) & 1)
#define LAST(a) a[sz(a) - 1]

typedef unsigned int uint;
typedef double dbl;
typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef pair <int, int> pii;
typedef unsigned char byte;

template <class T> T inline sqr(T x) { return x * x; }
template <class T> inline void relaxMin( T &a, T b ) { a = min(a, b); }
template <class T> inline void relaxMax( T &a, T b ) { a = max(a, b); }

string str( int i ) { char s[100]; sprintf(s, "%d", i); return string(s); }

template <class T> inline T sign( T x ) { return x > 0 ? 1 : (x < 0 ? -1 : 0); }
template <class T> inline T myAbs( T a ) { return a > 0 ? a : -a; }

#define DEBUG 1
void err( const char *fmt, ... )
{
  #if DEBUG
  va_list list;
  va_start(list, fmt);
  vfprintf(stderr, fmt, list);
  #endif
}

/* The main part */

const int maxn = 1010;

int sum, n, k, c[maxn][maxn];

int main()
{
  assert(freopen("input.txt", "r", stdin));
  assert(freopen("output.txt", "w", stdout));

  scanf("%d", &n);
  forn(s, n)
  {
    scanf("%d", &k);
    forn(i, k)
      forn(j, k)
        c[i][j] = (int)1e9;
    forn(i, k - 1)
    {
      int a, b;
      scanf("%d%d", &a, &b), a--, b--;
      c[a][b] = c[b][a] = 1;
    }
    forn(t, k)
      forn(i, k)
        forn(j, k)
          relaxMin(c[i][j], c[i][t] + c[t][j]);

    int ma = 0;
    forn(i, k)
      forn(j, k)
        relaxMax(ma, c[i][j]);
    sum += ma;
  }
  printf("%d\n", sum);
  return 0;
}


#include<iostream>
#include<vector>
#include<cstring>
#include<cmath>
#include<queue>
#include<stdio.h>
using namespace std;
int visited[102];
int n,comp;
int distance_root[102];
int parent[102][8];
void calculate_distance(int root,vector<int>v[102]){
    bool visited[102];
    memset(visited,false,sizeof(visited));
    distance_root[root]=0;
    parent[root][0]=-1;
    queue<int> q;

    q.push(root);
    visited[root]=true;
    while(!q.empty()){
        int x=q.front();

        q.pop();
        for(vector<int>::iterator it3=v[x].begin();it3!=v[x].end();it3++){
            if(!visited[*it3]){
                visited[*it3]=true;
                distance_root[*it3]=distance_root[x]+1;

                parent[*it3][0]=x;

                q.push(*it3);
            }
        }
    }
}
int lca(int a,int b){
    int lg=-1,i;
        if(distance_root[a]>distance_root[b])
            swap(a,b);
        for(i=distance_root[b];i;i>>=1)
            lg++;
        for(i =lg;i>=0;i--)
            if(parent[b][i]!=-1&&distance_root[a]<=distance_root[parent[b][i]])
                b=parent[b][i];
        if(a==b)
            return a;
        for(i=lg;i>=0;i--)
            if(parent[a][i]!=-1&&parent[a][i]!=parent[b][i])
                a=parent[a][i],b=parent[b][i];
        return parent[a][0];
}
int process(vector<int>v[102])
{
    int mark[102],i,j,sr;
    memset(visited,0,sizeof(visited));
    memset(mark,0,sizeof(mark));
    for(i=1;i<=comp;++i)
    {
        for(j=0;j<=7;++j)
        parent[i][j]=-1;
    }
    for(i=1;i<=comp;++i)
    if(v[i].size()==1)
    {
        sr=i;
        break;
    }
    calculate_distance(sr,v);
    for (j=1;j<=7;j++)
        for (i=1;i<=comp;i++)
            if(parent[i][j-1]!=-1)
                parent[i][j]=parent[parent[i][j-1]][j-1];

    int ans=0;
    for(i=1;i<comp;++i)
    {
        for(j=i+1;j<=comp;++j)
        {
            int id=lca(i,j);
            ans=max(ans,distance_root[i]+distance_root[j]-2*distance_root[id]);
        }
    }
    return ans;
}
int main()
{
    vector<int>v[102];
    int i,j,n1,n2;
    int ans=0;
    cin>>n;
    while(n--)
    {
        cin>>comp;
        for(i=1;i<=comp;++i)
        v[i].clear();
        for(i=1;i<=comp-1;++i)
        {
        cin>>n1>>n2;
            v[n1].push_back(n2);
            v[n2].push_back(n1);
        }
        ans+=process(v);
    }
    cout<<ans<<endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <climits>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <string>
#include <stack>
#include <set>
#include <map>
#include <deque>
#include <ctime>
using namespace std;
int visited[102];
int comp;
int distance_root[102];
int parent[102][8];
void calculate_distance(int root,vector<int>v[102]){
    bool visited[102];
    memset(visited,false,sizeof(visited));
    distance_root[root]=0;
    parent[root][0]=-1;
    queue<int> q;

    q.push(root);
    visited[root]=true;
    while(!q.empty()){
        int x=q.front();

        q.pop();
        for(vector<int>::iterator it3=v[x].begin();it3!=v[x].end();it3++){
            if(!visited[*it3]){
                visited[*it3]=true;
                distance_root[*it3]=distance_root[x]+1;

                parent[*it3][0]=x;

                q.push(*it3);
            }
        }
    }
}
int lca(int a,int b){
    int lg=-1,i;
        if(distance_root[a]>distance_root[b])
            swap(a,b);
        for(i=distance_root[b];i;i>>=1)
            lg++;
        for(i =lg;i>=0;i--)
            if(parent[b][i]!=-1&&distance_root[a]<=distance_root[parent[b][i]])
                b=parent[b][i];
        if(a==b)
            return a;
        for(i=lg;i>=0;i--)
            if(parent[a][i]!=-1&&parent[a][i]!=parent[b][i])
                a=parent[a][i],b=parent[b][i];
        return parent[a][0];
}
int process(vector<int>v[102])
{
    int mark[102],i,j,sr;
    memset(visited,0,sizeof(visited));
    memset(mark,0,sizeof(mark));
    for(i=1;i<=comp;++i)
    {
        for(j=0;j<=7;++j)
        parent[i][j]=-1;
    }
    for(i=1;i<=comp;++i)
    if(v[i].size()==1)
    {
        sr=i;
        break;
    }
    calculate_distance(sr,v);
    for (j=1;j<=7;j++)
        for (i=1;i<=comp;i++)
            if(parent[i][j-1]!=-1)
                parent[i][j]=parent[parent[i][j-1]][j-1];

    int ans=0;
    for(i=1;i<comp;++i)
    {
        for(j=i+1;j<=comp;++j)
        {
            int id=lca(i,j);
            ans=max(ans,distance_root[i]+distance_root[j]-2*distance_root[id]);
        }
    }
    return ans;
}
int main()
{
    freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
    vector<int>v[102];
    int i,j,n1,n2,n;
    int ans=0;
    cin>>n;
    while(n--)
    {
        cin>>comp;
        for(i=1;i<=comp;++i)
        v[i].clear();
        for(i=1;i<=comp-1;++i)
        {
        cin>>n1>>n2;
            v[n1].push_back(n2);
            v[n2].push_back(n1);
        }
        ans+=process(v);
    }
    cout<<ans<<endl;
    return 0;
}


#include<iostream>
#include<vector>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
int visited[102];
int comp;
int distance_root[102];
int parent[102][8];
void calculate_distance(int root,vector<int>v[102]){
    bool visited[102];
    memset(visited,false,sizeof(visited));
    distance_root[root]=0;
    parent[root][0]=-1;
    queue<int> q;

    q.push(root);
    visited[root]=true;
    while(!q.empty()){
        int x=q.front();

        q.pop();
        for(vector<int>::iterator it3=v[x].begin();it3!=v[x].end();it3++){
            if(!visited[*it3]){
                visited[*it3]=true;
                distance_root[*it3]=distance_root[x]+1;

                parent[*it3][0]=x;

                q.push(*it3);
            }
        }
    }
}
int lca(int a,int b){
    int lg=-1,i;
        if(distance_root[a]>distance_root[b])
            swap(a,b);
        for(i=distance_root[b];i;i>>=1)
            lg++;
        for(i =lg;i>=0;i--)
            if(parent[b][i]!=-1&&distance_root[a]<=distance_root[parent[b][i]])
                b=parent[b][i];
        if(a==b)
            return a;
        for(i=lg;i>=0;i--)
            if(parent[a][i]!=-1&&parent[a][i]!=parent[b][i])
                a=parent[a][i],b=parent[b][i];
        return parent[a][0];
}
int process(vector<int>v[102])
{
    int mark[102],i,j,sr;
    memset(visited,0,sizeof(visited));
    memset(mark,0,sizeof(mark));
    for(i=1;i<=comp;++i)
    {
        for(j=0;j<=7;++j)
        parent[i][j]=-1;
    }
    for(i=1;i<=comp;++i)
    if(v[i].size()==1)
    {
        sr=i;
        break;
    }
    calculate_distance(sr,v);
    for (j=1;j<=7;j++)
        for (i=1;i<=comp;i++)
            if(parent[i][j-1]!=-1)
                parent[i][j]=parent[parent[i][j-1]][j-1];

    int ans=0;
    for(i=1;i<comp;++i)
    {
        for(j=i+1;j<=comp;++j)
        {
            int id=lca(i,j);
            ans=max(ans,distance_root[i]+distance_root[j]-2*distance_root[id]);
        }
    }
    return ans;
}
int main()
{
   freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
    vector<int>v[102];
    int i,j,n1,n2,n;
    int ans=0;
    cin>>n;
    while(n--)
    {
        cin>>comp;
        for(i=1;i<=comp;++i)
        v[i].clear();
        for(i=1;i<=comp-1;++i)
        {
        cin>>n1>>n2;
            v[n1].push_back(n2);
            v[n2].push_back(n1);
        }
        ans+=process(v);
    }
    cout<<ans<<endl;
    return 0;
}


#include<iostream>
#include<vector>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
int visited[102];
int n,comp;
int distance_root[102];
int parent[102][8];
void calculate_distance(int root,vector<int>v[102]){
    bool visited[102];
    memset(visited,false,sizeof(visited));
    distance_root[root]=0;
    parent[root][0]=-1;
    queue<int> q;

    q.push(root);
    visited[root]=true;
    while(!q.empty()){
        int x=q.front();

        q.pop();
        for(vector<int>::iterator it3=v[x].begin();it3!=v[x].end();it3++){
            if(!visited[*it3]){
                visited[*it3]=true;
                distance_root[*it3]=distance_root[x]+1;

                parent[*it3][0]=x;

                q.push(*it3);
            }
        }
    }
}
int lca(int a,int b){
    int lg=-1,i;
        if(distance_root[a]>distance_root[b])
            swap(a,b);
        for(i=distance_root[b];i;i>>=1)
            lg++;
        for(i =lg;i>=0;i--)
            if(parent[b][i]!=-1&&distance_root[a]<=distance_root[parent[b][i]])
                b=parent[b][i];
        if(a==b)
            return a;
        for(i=lg;i>=0;i--)
            if(parent[a][i]!=-1&&parent[a][i]!=parent[b][i])
                a=parent[a][i],b=parent[b][i];
        return parent[a][0];
}
int process(vector<int>v[102])
{
	int mark[102],i,j,sr;
	memset(visited,0,sizeof(visited));
	memset(mark,0,sizeof(mark));
	for(i=1;i<=comp;++i)
	{
		for(j=0;j<=7;++j)
		parent[i][j]=-1;
	}
	for(i=1;i<=comp;++i)
	if(v[i].size()==1)
	{
		sr=i;
		break;
	}
	calculate_distance(sr,v);
	for (j=1;j<=7;j++)
        for (i=1;i<=comp;i++)
            if(parent[i][j-1]!=-1)
                parent[i][j]=parent[parent[i][j-1]][j-1];

	int ans=0;
	for(i=1;i<comp;++i)
	{
		for(j=i+1;j<=comp;++j)
		{
			int id=lca(i,j);
			ans=max(ans,distance_root[i]+distance_root[j]-2*distance_root[id]);
		}
	}
	return ans;
}
int main()
{
	vector<int>v[102];
    int i,j,n1,n2;
    int ans=0;
    cin>>n;
    while(n--)
    {
    	cin>>comp;
    	for(i=1;i<=comp;++i)
    	v[i].clear();
    	for(i=1;i<=comp-1;++i)
    	{
    	cin>>n1>>n2;
    		v[n1].push_back(n2);
    		v[n2].push_back(n1);
    	}
    	ans+=process(v);
    }
    cout<<ans<<endl;
    return 0;
}


#include<iostream>
#include<vector>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
int visited[102];
int comp;
int distance_root[102];
int parent[102][8];
void calculate_distance(int root,vector<int>v[102]){
    bool visited[102];
    memset(visited,false,sizeof(visited));
    distance_root[root]=0;
    parent[root][0]=-1;
    queue<int> q;

    q.push(root);
    visited[root]=true;
    while(!q.empty()){
        int x=q.front();

        q.pop();
        for(vector<int>::iterator it3=v[x].begin();it3!=v[x].end();it3++){
            if(!visited[*it3]){
                visited[*it3]=true;
                distance_root[*it3]=distance_root[x]+1;

                parent[*it3][0]=x;

                q.push(*it3);
            }
        }
    }
}
int lca(int a,int b){
    int lg=-1,i;
        if(distance_root[a]>distance_root[b])
            swap(a,b);
        for(i=distance_root[b];i;i>>=1)
            lg++;
        for(i =lg;i>=0;i--)
            if(parent[b][i]!=-1&&distance_root[a]<=distance_root[parent[b][i]])
                b=parent[b][i];
        if(a==b)
            return a;
        for(i=lg;i>=0;i--)
            if(parent[a][i]!=-1&&parent[a][i]!=parent[b][i])
                a=parent[a][i],b=parent[b][i];
        return parent[a][0];
}
int process(vector<int>v[102])
{
    int mark[102],i,j,sr;
    memset(visited,0,sizeof(visited));
    memset(mark,0,sizeof(mark));
    for(i=1;i<=comp;++i)
    {
        for(j=0;j<=7;++j)
        parent[i][j]=-1;
    }
    for(i=1;i<=comp;++i)
    if(v[i].size()==1)
    {
        sr=i;
        break;
    }
    calculate_distance(sr,v);
    for (j=1;j<=7;j++)
        for (i=1;i<=comp;i++)
            if(parent[i][j-1]!=-1)
                parent[i][j]=parent[parent[i][j-1]][j-1];

    int ans=0;
    for(i=1;i<comp;++i)
    {
        for(j=i+1;j<=comp;++j)
        {
            int id=lca(i,j);
            ans=max(ans,distance_root[i]+distance_root[j]-2*distance_root[id]);
        }
    }
    return ans;
}
int main()
{
    vector<int>v[102];
    int i,j,n1,n2,n;
    int ans=0;
    cin>>n;
    while(n--)
    {
        cin>>comp;
        for(i=1;i<=comp;++i)
        v[i].clear();
        for(i=1;i<=comp-1;++i)
        {
        cin>>n1>>n2;
            v[n1].push_back(n2);
            v[n2].push_back(n1);
        }
        ans+=process(v);
    }
    cout<<ans<<endl;
    return 0;
}


#include<iostream>
#include<vector>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
int visited[102];
int n,comp;
int distance_root[102];
int parent[102][8];
void calculate_distance(int root,vector<int>v[102]){
    bool visited[102];
    memset(visited,false,sizeof(visited));
    distance_root[root]=0;
    parent[root][0]=-1;
    queue<int> q;

    q.push(root);
    visited[root]=true;
    while(!q.empty()){
        int x=q.front();

        q.pop();
        for(vector<int>::iterator it3=v[x].begin();it3!=v[x].end();it3++){
            if(!visited[*it3]){
                visited[*it3]=true;
                distance_root[*it3]=distance_root[x]+1;

                parent[*it3][0]=x;

                q.push(*it3);
            }
        }
    }
}
int lca(int a,int b){
    int lg=-1,i;
        if(distance_root[a]>distance_root[b])
            swap(a,b);
        for(i=distance_root[b];i;i>>=1)
            lg++;
        for(i =lg;i>=0;i--)
            if(parent[b][i]!=-1&&distance_root[a]<=distance_root[parent[b][i]])
                b=parent[b][i];
        if(a==b)
            return a;
        for(i=lg;i>=0;i--)
            if(parent[a][i]!=-1&&parent[a][i]!=parent[b][i])
                a=parent[a][i],b=parent[b][i];
        return parent[a][0];
}
int process(vector<int>v[102])
{
    int mark[102],i,j,sr;
    memset(visited,0,sizeof(visited));
    memset(mark,0,sizeof(mark));
    for(i=1;i<=comp;++i)
    {
        for(j=0;j<=7;++j)
        parent[i][j]=-1;
    }
    for(i=1;i<=comp;++i)
    if(v[i].size()==1)
    {
        sr=i;
        break;
    }
    calculate_distance(sr,v);
    for (j=1;j<=7;j++)
        for (i=1;i<=comp;i++)
            if(parent[i][j-1]!=-1)
                parent[i][j]=parent[parent[i][j-1]][j-1];

    int ans=0;
    for(i=1;i<comp;++i)
    {
        for(j=i+1;j<=comp;++j)
        {
            int id=lca(i,j);
            ans=max(ans,distance_root[i]+distance_root[j]-2*distance_root[id]);
        }
    }
    return ans;
}
int main()
{
    vector<int>v[102];
    int i,j,n1,n2;
    int ans=0;
    cin>>n;
    while(n--)
    {
        cin>>comp;
        for(i=1;i<=comp;++i)
        v[i].clear();
        for(i=1;i<=comp-1;++i)
        {
        cin>>n1>>n2;
            v[n1].push_back(n2);
            v[n2].push_back(n1);
        }
        ans+=process(v);
    }
    cout<<ans<<endl;
    return 0;
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int dist[102][102];
const int inf=1<<29;
int c;
int main(){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);/**/
	int t,n;
	scanf("%d",&t);
	while(t--){
			   scanf("%d",&n);
			   for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)if(i==j)dist[i][j]=0;else dist[i][j]=inf;
			   for(int i=1;i<n;i++){
			   		   int x,y;
			   		   scanf("%d%d",&x,&y);
			   		   dist[x][y]=dist[y][x]=1;
		}
		for(int k=1;k<=n;k++)for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)
		if(dist[i][k]+dist[j][k]<dist[i][j])
		dist[i][j]=dist[i][k]+dist[k][j];
		int mx=0;
		for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)mx=max(mx,dist[i][j]);
		c+=mx;
	}
	printf("%d\n",c);

	return 0;
}


#include <iostream>
#include <vector>
#include <string.h>
using namespace std;
bool g[102][102];
bool vis[102];
int dep,far;
int v;
void dfs(int x,int depth){
	 vis[x]=true;
	 if(dep<depth){dep=depth;far=x;}
	 for(int i=1;i<=v;i++)if(g[x][i]&&!vis[i])dfs(i,depth+1);
}
int solve(){
	 memset(vis,0,sizeof(vis));
	 memset(g,0,sizeof(g));
	 cin>>v;
	 for(int i=1;i<v;i++){
	 		 int x,y;
	 		 cin>>x>>y;
	 		 g[x][y]=g[y][x]=true;
	}
	dfs(1,0);
	dfs(far,0);
	return dep;
}
int main(){
	int t;
	cin>>t;
	int sum=0;
	while(t--){sum+=solve();}
	cout<<sum;
	return 0;
}


#include <stdio.h>
#include <string.h>
using namespace std;
int dist[102][102];
const int inf=1<<30;
int c;
int main(){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	int t,n;
	scanf("%d",&t);
	while(t--){
			   scanf("%d",&n);
			   for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)if(i==j)dist[i][j]=0;else dist[i][j]=inf;
			   for(int i=1;i<n;i++){
			   		   int x,y;
			   		   scanf("%d%d",&x,&y);
			   		   dist[x][y]=dist[y][x]=1;
		}
		for(int k=1;k<=n;k++)for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)
		if(dist[i][k]+dist[j][k]<dist[i][j])
		dist[i][j]=dist[i][k]+dist[k][j];
		int mx=0;
		for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)if(mx<dist[i][j])mx=dist[i][j];
		c+=mx;
	}
	printf("%d\n",c);
	return 0;
}


#include <stdio.h>
#include <vector>
#include <string.h>
using namespace std;
bool g[102][102];
bool vis[102];
int dep,far;
int v;
void dfs(int x,int depth){
	 vis[x]=true;
	 if(dep<depth){dep=depth;far=x;}
	 for(int i=1;i<=v;i++)if(g[x][i]&&!vis[i])dfs(i,depth+1);
}
int solve(){
	 memset(vis,0,sizeof(vis));
	 memset(g,0,sizeof(g));
	 scanf("%d",&v);
	 for(int i=1;i<v;i++){
	 		 int x,y;
	 		 scanf("%d%d",&x,&y);
	 		 g[x][y]=g[y][x]=true;
	}
	dfs(1,0);
	dfs(far,0);
	return dep;
}
int main(){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	int t;
	scanf("%d",&t);
	int sum=0;
	while(t--){sum+=solve();}
	printf("%d\n",sum);
	return 0;
}


#include <iostream>
#include <vector>
#include <string.h>
using namespace std;
bool g[102][102];
bool vis[102];
int dep,far;
int v;
void dfs(int x,int depth){
	 vis[x]=true;
	 if(dep<depth){dep=depth;far=x;}
	 for(int i=1;i<=v;i++)if(g[x][i]&&!vis[i])dfs(i,depth+1);
}
int solve(){
	 memset(vis,0,sizeof(vis));
	 memset(g,0,sizeof(g));
	 cin>>v;
	 for(int i=1;i<v;i++){
	 		 int x,y;
	 		 cin>>x>>y;
	 		 g[x][y]=g[y][x]=true;
	}
	dfs(1,0);
	dfs(far,0);
	return dep;
}
int main(){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	int t;
	cin>>t;
	int sum=0;
	while(t--){sum+=solve();}
	cout<<sum;
	return 0;
}


#include <stdio.h>
#include <vector>
#include <string.h>
using namespace std;
bool g[102][102];
bool vis[102];
int dep,far;
int v;
void dfs(int x,int depth){
	 vis[x]=true;
	 if(dep<depth){dep=depth;far=x;}
	 for(int i=1;i<=v;i++)if(g[x][i]&&!vis[i])dfs(i,depth+1);
}
int solve(){
	 memset(vis,0,sizeof(vis));
	 memset(g,0,sizeof(g));
	 scanf("%d",&v);
	 for(int i=1;i<v;i++){
	 		 int x,y;
	 		 scanf("%d%d",&x,&y);
	 		 g[x][y]=g[y][x]=true;
	}
	dfs(1,0);
	memset(vis,0,sizeof(vis));
	dfs(far,0);
	return dep;
}
int main(){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);/**/
	int t;
	scanf("%d",&t);
	int sum=0;
	while(t--){sum+=solve();}
	printf("%d\n",sum);
	return 0;
}


/*  求一棵树上距离最远的两个顶点的距离,题目给m棵树，求所以树连接起来的最长长度（每个树最远距离加和）
 *  可以随便选择一个点开始进行bfs或者dfs，
从而找到离该点最远的那个点（可以证明，离树上任意一点最远的点一定是树的某条直径的两端点之一；
树的直径：树上的最长简单路径）。再从找到的点出发，找到据该点的最远点，那么这两点就确定了树的一条直径，两点间距即为所求距离。*/
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
#define N 110
#define clr(a) memset(a,0,sizeof(a))
#define F1(i,n) for(int i=0;i<n;i++)
#define F2(i,n) for(int i=1;i<=n;i++)
int n;                        //每棵树对应的顶点数
vector<int>vv[N];             //邻接表存边的关系
int le,ri,length;        //距离最长的两端点和长度;
void bfs(int root)
{
    int flag[N];             //标记数组
    int cnt[N];             //记录每个点所在的层数(根结点层数为0)
    clr(cnt);
    clr(flag);
    queue<int>q;
    while(!q.empty())
        q.pop();
    q.push(root);
    flag[root]=1;
    while(!q.empty())
    {
        int u=q.front();
        if(root==1)
            le=u;
        else
            ri=u;
        q.pop();
        F1(i,vv[u].size())
        {
            int v=vv[u][i];
            cnt[v]=cnt[u]+1;
            if(flag[v]==0)
            {
                flag[v]=1;
                q.push(v);
            }
        }
    }
    if(root==1)
        length=cnt[le];
    else
        length=cnt[ri];
}
int main()
{
    int m,sum;                    //m棵树
    while(~scanf("%d",&m))
    {
        sum=0;
        while(m--)
        {
            int u,v;
            scanf("%d",&n);
            F2(i,n)
                vv[i].clear();
            F2(i,n-1)                     //n个点，n-1对边的关系
            {
                scanf("%d%d",&u,&v);
                vv[u].push_back(v);
                vv[v].push_back(u);
            }
            bfs(1);
            bfs(le);
            sum+=length;
        }
        printf("%d\n",sum);
    }
    return 0;
}


/*  求一棵树上距离最远的两个顶点的距离,题目给m棵树，求所以树连接起来的最长长度（每个树最远距离加和）
 *  可以随便选择一个点开始进行bfs或者dfs，
从而找到离该点最远的那个点（可以证明，离树上任意一点最远的点一定是树的某条直径的两端点之一；
树的直径：树上的最长简单路径）。再从找到的点出发，找到据该点的最远点，那么这两点就确定了树的一条直径，两点间距即为所求距离。*/
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
#define N 110
#define clr(a) memset(a,0,sizeof(a))
#define F1(i,n) for(int i=0;i<n;i++)
#define F2(i,n) for(int i=1;i<=n;i++)
int n;                        //每棵树对应的顶点数
vector<int>vv[N];             //邻接表存边的关系
int le,ri,length;        //距离最长的两端点和长度;
void bfs(int root)
{
    int flag[N];             //标记数组
    int cnt[N];             //记录每个点所在的层数(根结点层数为0)
    clr(cnt);
    clr(flag);
    queue<int>q;
    while(!q.empty())
        q.pop();
    q.push(root);
    flag[root]=1;
    while(!q.empty())
    {
        int u=q.front();
        if(root==1)
            le=u;
        else
            ri=u;
        q.pop();
        F1(i,vv[u].size())
        {
            int v=vv[u][i];
            cnt[v]=cnt[u]+1;
            if(flag[v]==0)
            {
                flag[v]=1;
                q.push(v);
            }
        }
    }
    if(root==1)
        length=cnt[le];
    else
        length=cnt[ri];
}
int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    int m,sum;                    //m棵树
    while(~scanf("%d",&m))
    {
        sum=0;
        while(m--)
        {
            int u,v;
            scanf("%d",&n);
            F2(i,n)
                vv[i].clear();
            F2(i,n-1)                     //n个点，n-1对边的关系
            {
                scanf("%d%d",&u,&v);
                vv[u].push_back(v);
                vv[v].push_back(u);
            }
            bfs(1);
            bfs(le);
            sum+=length;
        }
        printf("%d\n",sum);
    }
    return 0;
}


/*  求一棵树上距离最远的两个顶点的距离,题目给m棵树，求所以树连接起来的最长长度（每个树最远距离加和）
 *  可以随便选择一个点开始进行bfs或者dfs，
从而找到离该点最远的那个点（可以证明，离树上任意一点最远的点一定是树的某条直径的两端点之一；
树的直径：树上的最长简单路径）。再从找到的点出发，找到据该点的最远点，那么这两点就确定了树的一条直径，两点间距即为所求距离。*/
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
#define N 110
#define clr(a) memset(a,0,sizeof(a))
#define F1(i,n) for(int i=0;i<n;i++)
#define F2(i,n) for(int i=1;i<=n;i++)
int n;                        //每棵树对应的顶点数
vector<int>vv[N];             //邻接表存边的关系
int le,ri,length;        //距离最长的两端点和长度;
void bfs(int root)
{
    int flag[N];             //标记数组
    int cnt[N];             //记录每个点所在的层数(根结点层数为0)
    clr(cnt);
    clr(flag);
    queue<int>q;
    while(!q.empty())
        q.pop();
    q.push(root);
    flag[root]=1;
    while(!q.empty())
    {
        int u=q.front();
        if(root==1)
            le=u;
        else
            ri=u;
        q.pop();
        F1(i,vv[u].size())
        {
            int v=vv[u][i];
            cnt[v]=cnt[u]+1;
            if(flag[v]==0)
            {
                flag[v]=1;
                q.push(v);
            }
        }
    }
    if(root==1)
        length=cnt[le];
    else
        length=cnt[ri];
}
int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdin);
    int m,sum;                    //m棵树
    while(~scanf("%d",&m))
    {
        sum=0;
        while(m--)
        {
            int u,v;
            scanf("%d",&n);
            F2(i,n)
                vv[i].clear();
            F2(i,n-1)                     //n个点，n-1对边的关系
            {
                scanf("%d%d",&u,&v);
                vv[u].push_back(v);
                vv[v].push_back(u);
            }
            bfs(1);
            bfs(le);
            sum+=length;
        }
        printf("%d\n",sum);
    }
    return 0;
}


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
#define N 110
#define clr(a) memset(a,0,sizeof(a))
#define F1(i,n) for(int i=0;i<n;i++)
#define F2(i,n) for(int i=1;i<=n;i++)
int n;                        //每棵树对应的顶点数
vector<int>vv[N];             //邻接表存边的关系
int le,ri,length;        //距离最长的两端点和长度;
void bfs(int root)
{
    int flag[N];             //标记数组
    int cnt[N];             //记录每个点所在的层数(根结点层数为0)
    clr(cnt);
    clr(flag);
    queue<int>q;
    while(!q.empty())
        q.pop();
    q.push(root);
    flag[root]=1;
    while(!q.empty())
    {
        int u=q.front();
        if(root==1)
            le=u;
        else
            ri=u;
        q.pop();
        F1(i,vv[u].size())
        {
            int v=vv[u][i];
            cnt[v]=cnt[u]+1;
            if(flag[v]==0)
            {
                flag[v]=1;
                q.push(v);
            }
        }
    }
    if(root==1)
        length=cnt[le];
    else
        length=cnt[ri];
}
int main()
{
    int m,sum;                    //m棵树
    while(~scanf("%d",&m))
    {
        sum=0;
        while(m--)
        {
            int u,v;
            scanf("%d",&n);
            F2(i,n)
                vv[i].clear();
            F2(i,n-1)                     //n个点，n-1对边的关系
            {
                scanf("%d%d",&u,&v);
                vv[u].push_back(v);
                vv[v].push_back(u);
            }
            bfs(1);
            bfs(le);
            sum+=length;
        }
        printf("%d\n",sum);
    }
    return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
#define N 2000
#define M 2000

typedef struct node1
{
    int v;
    int len;
    node1 *nex;
}NODE1;

typedef struct node2
{
    int v;
    node2 *nex;
}NODE2;

NODE1 edg1[N*2],*link1[N];
NODE2 edg2[M*2],*link2[N];
int tree[N],hh[N],in[N];
int cnt1,cnt2;
int _max;
int dis[N];
int n,m,t;
void init()
{
    memset(link1,0,sizeof(link1));
    memset(link2,0,sizeof(link2));
    memset(tree,-1,sizeof(tree));
    memset(hh,0,sizeof(hh));
    memset(in,0,sizeof(in));
    cnt1=cnt2=0;
}
int find(int x)
{
    if(tree[x]==x)
        return x;
    return tree[x]=find(tree[x]);
}
void scanf_(int &num)
{
    char in;
    while((in=getchar()) > '9' || in<'0') ;
    num=in-'0';
    while(in=getchar(),in>='0'&&in<='9')
        num*=10,num+=in-'0';
}
void insert(int a,int b,int c)
{
    edg1[cnt1].v=b;
    edg1[cnt1].len=c;
    edg1[cnt1].nex=link1[a];
    link1[a]=&edg1[cnt1++];

    edg1[cnt1].v=a;
    edg1[cnt1].len=c;
    edg1[cnt1].nex=link1[b];
    link1[b]=&edg1[cnt1++];
}
void insert(int a,int b)
{
    edg2[cnt2].v=b;
    edg2[cnt2].nex=link2[a];
    link2[a]=&edg2[cnt2++];

    edg2[cnt2].v=a;
    edg2[cnt2].nex=link2[b];
    link2[b]=&edg2[cnt2++];
}
void solve(int n)
{
    int i;
    int temp;
    tree[n]=n;
    for(NODE1 *p=link1[n];p;p=p->nex)
    {
        temp=p->v;
        if(hh[temp]==0)
        {
            if(tree[temp]!=-1)
                continue;
             dis[temp]=dis[n]+p->len;
               solve(temp);
            tree[temp]=n;
        }
    }
    hh[n]=1;
    for(NODE2 *p=link2[n];p;p=p->nex)
    {
        temp=p->v;
        if(hh[temp])
            _max=max(_max,dis[n]+dis[temp]-2*dis[find(temp)]);
    }
}

int main()
{
    int i,j;
    int a,b;
    int ans;
    freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
    while(~scanf("%d",&t))
    {
        ans=0;
        while(t--)
        {
            scanf("%d",&n);
            init();
            for(i=1;i<n;i++)
            {
                scanf("%d%d",&a,&b);
                in[a]++;in[b]++;
                insert(a,b,1);
            }
            for(i=1;i<=n;i++)
                if(in[i]==1)
                    for(j=1;j<=n;j++)
                        if(in[j]==1 && i!=j)
                            insert(i,j);
            _max=1;
            for(i=1;i<=n;i++)
                if(in[i]!=1)
                {
                    solve(i);
                    break;
                }
            ans+=_max;
        }
        printf("%d\n",ans);
    }

}


#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
#define N 2000
#define M 200000

typedef struct node1
{
    int v;
    int len;
    node1 *nex;
}NODE1;

typedef struct node2
{
    int v;
    node2 *nex;
}NODE2;

NODE1 edg1[N*2],*link1[N];
NODE2 edg2[M*2],*link2[N];
int tree[N],hh[N],in[N];
int cnt1,cnt2;
int _max;
int dis[N];
int n,m,t;
void init()
{
    memset(link1,0,sizeof(link1));
    memset(link2,0,sizeof(link2));
    memset(tree,-1,sizeof(tree));
    memset(hh,0,sizeof(hh));
    memset(in,0,sizeof(in));
    cnt1=cnt2=0;
}
int find(int x)
{
    if(tree[x]==x)
        return x;
    return tree[x]=find(tree[x]);
}
void scanf_(int &num)
{
    char in;
    while((in=getchar()) > '9' || in<'0') ;
    num=in-'0';
    while(in=getchar(),in>='0'&&in<='9')
        num*=10,num+=in-'0';
}
void insert(int a,int b,int c)
{
    edg1[cnt1].v=b;
    edg1[cnt1].len=c;
    edg1[cnt1].nex=link1[a];
    link1[a]=&edg1[cnt1++];

    edg1[cnt1].v=a;
    edg1[cnt1].len=c;
    edg1[cnt1].nex=link1[b];
    link1[b]=&edg1[cnt1++];
}
void insert(int a,int b)
{
    edg2[cnt2].v=b;
    edg2[cnt2].nex=link2[a];
    link2[a]=&edg2[cnt2++];

    edg2[cnt2].v=a;
    edg2[cnt2].nex=link2[b];
    link2[b]=&edg2[cnt2++];
}
void solve(int n)
{
    int i;
    int temp;
    tree[n]=n;
    for(NODE1 *p=link1[n];p;p=p->nex)
    {
        temp=p->v;
        if(hh[temp]==0)
        {
            if(tree[temp]!=-1)
                continue;
             dis[temp]=dis[n]+p->len;
               solve(temp);
            tree[temp]=n;
        }
    }
    hh[n]=1;
    for(NODE2 *p=link2[n];p;p=p->nex)
    {
        temp=p->v;
        if(hh[temp])
            _max=max(_max,dis[n]+dis[temp]-2*dis[find(temp)]);
    }
}

int main()
{
    int i,j;
    int a,b;
    int ans;
    freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
    while(~scanf("%d",&t))
    {
        ans=0;
        while(t--)
        {
            scanf("%d",&n);
            init();
            for(i=1;i<n;i++)
            {
                scanf("%d%d",&a,&b);
                in[a]++;in[b]++;
                insert(a,b,1);
            }
            for(i=1;i<=n;i++)
                if(in[i]==1)
                    for(j=1;j<=n;j++)
                        if(in[j]==1 && i!=j)
                            insert(i,j);
            _max=1;
            for(i=1;i<=n;i++)
                if(in[i]!=1)
                {
                    solve(i);
                    break;
                }
            ans+=_max;
        }
        printf("%d\n",ans);
    }

}