#include <bits/stdc++.h>

using namespace std;

int ans,n,cnt;

int f[5010][5010];

struct node
{
	int tag, fa;
	int L, R;
}T[10010];

string line;
map<int,int> ha;
int num[5010];


void dfs(int now){
	if (T[now].tag==-1) return ;
//	cout << now<<" "<<ans<<endl;
	
	int pnow;
	if (ha.find(now)==ha.end()) pnow = ha[now] = cnt++;
		else pnow = ha[now];
	
	//int pnow=0,psonl=0,psonr=0;

	int psonl;

	if (T[T[now].L].tag>=0){
		f[pnow][T[T[now].L].tag]++;
		if (num[T[T[now].L].tag]>1) ans=max(ans,1);
	}else{
		if (ha.find(T[now].L)==ha.end()) psonl = ha[T[now].L] = cnt++;
			else psonl = ha[T[now].L];
		dfs(T[now].L);
		for (int j=0;j<=n;j++){
		 	f[pnow][j]+=f[psonl][j];
		}
	}
	
	int psonr;

	
	if (T[T[now].R].tag>=0){
		f[pnow][T[T[now].R].tag]++;
		if (num[T[T[now].R].tag]>1) ans=max(ans,1);
	}else{
		if (ha.find(T[now].R)==ha.end()) psonr = ha[T[now].R] = cnt++;
			else psonr = ha[T[now].R];
		dfs(T[now].R);
		for (int j=0;j<=n;j++){
			f[pnow][j]+=f[psonr][j];
		}
	}
	
	int cal=0;
	for (int j=0;j<=n;j++){
		cal += (num[j]-f[pnow][j])>0 && f[pnow][j]>0;
	}
//	cout << now <<"!!"<<cal<<endl;
	ans= max(ans,cal);
//	cout <<pnow<<" "<<psonl<<" "<<psonr<<endl;
//	if (pnow>5005 || psonl>5005 || psonr>5005) while (1);
}


int main()
{
	ios::sync_with_stdio(false);
	int cas = 0;
	while (getline(cin, line)) {
		if (line == "( )") break;
		int tot = 0;
		int now = 0; 	//root
		memset(T,0,sizeof(T));
		T[now].L = T[now].R = 0;
		T[0].tag = -2;
	//	cout <<line <<endl;
		memset(num,0,sizeof(num));
		for (int i = 1; i < line.size()-1 ; i++) {
			if (line[i] == ' ') continue;
			//cout <<i<<endl;
			//
			
			if (line[i] == '(') {
				
				if (T[now].L == 0) {
					T[now].L = ++tot;
					T[tot].fa = now;
					now = T[now].L;
				}
				else
				if (T[now].R == 0) {
					T[now].R = ++tot;
					T[tot].fa = now;
					now = T[now].R;
				}
				T[now].tag = -2; //not leaf;
			}
			else
			if (line[i] == ')') {
				now = T[now].fa;
			}
			else {
				if (T[now].L ==0 ){
					T[now].L = ++tot;
					T[tot].fa = now;
					now = tot;
				}else{
					T[now].R = ++tot;
					T[tot].fa = now;
					now = tot;
				}
				
				if (line[i] == '-') {
					T[now].tag = -1;
					now = T[now].fa;
					i++;
					continue;
				}

				int delta = 0;
				while (i < line.size() && isdigit(line[i])) {
					delta = delta * 10 + (line[i] - '0');
					i++;
				}
				i--;
	//			cout << now<<"!"<<delta<<endl;
				num[delta]++;
				T[now].tag = delta;
				now = T[now].fa;
			}

	//		cout << i<<" "<<now<<endl;
		}
		/*
		cout << tot<<endl;
		for (int i=0;i<=tot;i++)
			cout << i<<" "<<T[i].L<<" "<<T[i].R<<" "<<T[i].tag<<endl;
	*/
		//	break;
		//while (1);
		ans = 0;
		n = 5000;
		ha.clear();
		cnt=0;
		memset(f,0,sizeof(f));
		dfs(0);
		//cout << cnt<<endl;
		printf("Tree %d: %d\n",++cas,ans);
		//break;
	}
	return 0;
}
