#include<iostream>
#include<vector>
#include<string>
#include<queue>


using namespace std;

int bfs(vector<vector<int> > &G, int root, bool pathtracing){
	vector<bool> visited = vector<bool>(G.size(),false);
	queue<int> quepasa;
	vector<int> parents = vector<int>(G.size());
	quepasa.push(root);
	visited[root]=true;
	parents[root]=root;
	int vertex;
	while(true){
		vertex=quepasa.front();
		quepasa.pop();
		
		for(int i=0; i<G[vertex].size();i++){
			if(not visited[G[vertex][i]]){
				visited[G[vertex][i]] = true;
				parents[G[vertex][i]] = vertex;
				quepasa.push(G[vertex][i]);
			}
		}
		if(quepasa.empty()){
			if(pathtracing){
				int pathlength = 0;
				while(vertex != root){
					vertex = parents[vertex];
					pathlength += 100;
				}
				return pathlength;
			}
			else{
				return vertex;
			}
		}
	}
}

void test(){
	int n;
	cin>>n;
	vector<vector<int> > Graph = vector<vector<int> >(n, vector<int>(0));
	int a,b;
	for(int i = 0; i < n-1; i++){
		cin>>a>>b;
		Graph[a].push_back(b);
		Graph[b].push_back(a);
	}
	a=bfs(Graph,0,false);
	cout<<bfs(Graph,a,true)<<'\n';
	return;
}


int main(){
//	ios_base::sync_with_stdio(false);
//	cin.tie(NULL);
	int T;
	cin>>T;
	while(T-->0){
		test();
	}
	return 0;
}