#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int n, colors[20], nodes[20][20], c;

void fill (int node){
	int x=1, i, a;
	bool no=false;
	
	while (no==false){
		no=true;
		for (i=1; i<20; ++i){
			if (nodes[node][i]==1){
				if (x==colors[i]){
					no=false;
					++x;
					break;
				}
			}
		}
	}
	
	colors[node]=x;
	
	for (i=0; i<20; ++i){
		if (nodes[node][i]==1 && colors[i]==-1){
			fill(i);
		}
	}
	
	return;
}

int main (){
	freopen ("data5.txt", "r", stdin);
	freopen ("out5.txt", "w", stdout);
	int z, i, a, x, y;
	
	for (z=0; z<5; ++z){
		cin >> n;
		for (i=0; i<20; ++i){
			colors[i]=-1;
			for (a=0; a<20; ++a){
				nodes[i][a]=0;
			}
		}
		for (i=0; i<n; ++i){
			cin >> x >> y;
			nodes[x][y]=1;
			nodes[y][x]=1;
		}
		fill(1);
		c=0;
		for (i=0; i<20; ++i){
			if (colors[i]>c){
				c=colors[i];
			}
		}
		if (c>4){
			cout << 0 << endl;
		}
		else {
			cout << c << endl;
		}
	}
	
	return 0;
} 

