void main(){
	int i,j,num,count[10]={0};
	int stopskip[10][21]={0};
	scanf("%d",&num);
	for (i=1;i<=num;i++){
	    for (j=0;j<=stopskip[i][0];j++)
		   scanf("%d",&stopskip[i][j]);
	}
	for (i=1;i<=num;i++){
		if (stopskip[i][0]==0)
		count[i]=time;
	else if (stopskip[i][0]==1){
		if (stopskip[i][1]>=time)
			count[i]=time;
		else if (stopskip[i][1]<time&&stopskip[i][1]>=time-3)
			count[i]=stopskip[i][1];
		else count[i]=time-3;
	}
	}
	for (i=1;i<=num;i++){
		for (j=stopskip[i][0];j>1;j--){
	        if (((stopskip[i][j]+3*(j-1))>time)||(stopskip[i][j]==0))
	            continue;
		    else if ((stopskip[i][j]+3*(j-1)>time-3)&&(stopskip[i][j]+3*(j-1)<=time)){
				count[i]=stopskip[i][j];
				break;
			}
		    else{
				count[i]=(time-(stopskip[i][j]+3*j)+stopskip[i][j]);
	       break;
			}
		}
	}
for (i=1;i<=num;i++)
printf("%d\n",count[i]);
}


int main()
{
	int a[60];
	int n,m, i = 0, j = 0, count = 60;
	scanf("%d", &m);
	for (j = 0; j < m; j++)
	{
		count = 60;
	scanf("%d", &n);
	for (i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
	}

	for (i = 0; i < n; i++)
	{
		if (a[i] < count)
		{
			if (a[i] < count - 3)
			{
				count -= 3;
			}
			else
			{
				count = a[i];
				break;
			}
		}
		else
			break;
	}

	printf("%d\n", count);
	}
	return 0;
}


int main()
{
	int iCase,n,i,count,a[20];
	cin>>iCase;
	while(iCase--)
	{
		count=60;
		cin>>n;
		for(i=0;i<n;i++)
		{
			cin>>a[i];
		}
		for(i=0;i<n;i++)
		{
			if(a[i]+3*i>60) break;
			if(a[i]+3*(i+1)<=60) count-=3;
			if(a[i]+3*(i+1)>60) count=a[i];
		}
		cout<<count<<endl;
	}
	return 0;
}


int main()
{
        int n;
        int fail[60];

        cin>>n;

        while(n--)
        {
                int m;
                int i;
                cin>>m;
                for(i=0;i<m;i++)
                        cin>>fail[i];

                int count;

                if(m==0)
                {
                        cout<<60<<endl;
                        continue;
                }
                for(i=0;i<m;i++)
                {
                        if(fail[i]+3*i>=60)
                        {
                                cout<<60-3*i<<endl;
                                break;
                        }
                        if(fail[i]+3*(i+1)>60)
                        {
                                cout<<fail[i]<<endl;
                                break;
                        }
                }

                if(i==m)
                        cout<<60-3*m<<endl;
        }
        return 0;
}


int main(){
	int nCases, n, t;
	int wasteTime;

	cin >> nCases;
	while (nCases--){
		cin >> n;
		wasteTime = 0;
		for (int i = 0; i < n; i++){
			cin >> t;
			t += i * 3;
			if (t + 3 <= 60)
				wasteTime += 3;
			else if (t < 60 && t + 3 > 60)
				wasteTime += (60 - t);
		}

		cout << 60 - wasteTime << endl;
	}
	return 0;
}


void main()
{
  int z,i,j,n,t,count,time,tem,pre,go;
  char dd='0';
  scanf("%d",&t);
  for(z=0;z<t;z++)
{
	for(;;)
	{
   scanf("%c",&dd);
   if(dd=='\n') break;
    scanf("%d",&go);
	}
  scanf("%d",&n);
  if(n==0) {printf("60\n");continue;}
  count=0;time=0;tem=0;pre=0;
  for(i=0;i<n;i++)
{
  scanf("%d",&tem);
  pre=time;
  time=tem+3*(i+1);
  if(time<60) count=tem;
 else
{
  if(time>=63) {count=count+60-pre;break;}
  else
{
   count=tem;
  break;
}
}
}
if(time<=60) count=count+60-time;
printf("%d\n",count);
}
}


int main()
{
	int n,num[20],m,sum;
	cin>>n;
	while(n)
	{
		sum=0;
		cin>>m;
		for(int i=0;i<m;i++)
		{
			cin>>num[i];
		}
		for(int i=0;i<m;i++)
		{
			if((num[i]+3*(i+1))>63)
			{
				sum=num[i-1]+60-num[i-1]-3*i;
				break;
			}
			else if((num[i]+3*(i+1))>=60)
			{
				sum=num[i];
				break;
			}
		}
		if(sum==0)
		{
			sum=60-m*3;
		}
		if(m==0)
		cout<<60<<endl;
		else
		cout<<sum<<endl;
		n--;
	}

	return 0;
}


/*???????*/
struct information
{
	int t;
	int s[20];
}children[N];

void main()
{
	int n,i,j,p;
	int num[N];
	scanf("%d",&n);
	/*???????*/
	for(i=0;i<n;i++)
	{
				scanf("%d",&children[i].t);
		for(j=0;j<children[i].t;j++)
		{
			scanf("%d",&children[i].s[j]);
		}
	}
	/*????????????*/
	for(i=0;i<n;i++)
	{
		p=children[i].t;
		if(p==0)
			num[i]=60;
		else
		{
			for(j=0;j<p;)
			{
				if((children[i].s[j]+3*j)<57)
					j++;
				else
					break;
			}
		        if((children[i].s[j]+3*j)<=60&&(children[i].s[j]+3*j>57))
				num[i]=children[i].s[j];
			else
				num[i]=60-3*j;
		}
	}

		for(i=0;i<n;i++)
	{
		printf("%d\n",num[i]);
	}
}


int main()
{
    int n=0,i=0;
	int minnum=60;
	scanf("%d",&n);
	for(i=0;i<n;i++){
        int m;
	    scanf("%d",&m);
		int p=0;
		for(p=0;p<m;p++){
			int number;
			scanf("%d",&number);
			if((number+3*p)<=60){
				if((60-number-(3*p)-3)>=0)
					minnum=60-(3*p)-3;
				else if((60-number-(3*p)-3)<0)
                    minnum=number;
			}
		}
		printf("\n%d\n",minnum);
	}
	return 0;
}


/**
* @file 1000010424_6.cpp
* @author ???
* @date 2010?11?24
* @description
* ??????:1049 ????
*/

int main()
{
	int n, badNum;								//?????????????
	int i, j;									//?????
	int badTotal, time, place, lastPlace;		//??????????????????

	cin >> n;

	for(i = 1; i <= n; i++)
	{
		cin >> badNum;							//????????
		time = 0;
		badTotal = 0;
		lastPlace = 0;

		for(j = 1; j <= badNum; j++)
		{
			cin >> place;

			time += place - lastPlace;			//???????????

			if(time < 60)						//??????
			{
				if(time <= 57)
				{
					time += 3;					//time????????
					badTotal += 3;
				}
				else
				{
					badTotal += 60 - time;
					time += 3;
				}
			}
			else
				;

			lastPlace = place;
		}

		cout << 60 - badTotal << endl;
	}

	return 0;
}


int main()
{
	int n,k,a[60],sum=0,p;
	cin>>n;
	for(int i=1;i<=n;i++)
	{memset(a,0,sizeof(a));
		cin>>k;
		if(k==0) cout<<"60"<<endl;
		else{
		for(int j=0;j<k;j++)
			cin>>a[j];
		for(int j=k-1;j>0;j--)
		{
			a[j]=a[j]-a[j-1];

		}
		for(p=0;p<k;p++)
		{if(sum+a[p]+3<=60)
			sum+=a[p]+3;
		else if(sum+a[p]<=60)
			{
			cout<<sum+a[p]-3*p<<endl;
			break;}
		else {
			cout<<60-3*p<<endl;
		break;}
		}
		if(p==k) cout<<60-3*p<<endl;
		sum=0;

		}

	}
	return 0;
}


/*
 * 1.cpp
 *
 *  Created on: 2011-12-19
 *      Author: 1100012870
 */
int main()
{
	int i,j,n,m,time,num,x,y;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>m;
		time=0;
		num=0;
		x=0;
		for(j=1;j<=m;j++){
			cin>>x;
			num=x;
			if(x+time>=60){
				break;
			}else{
				time+=3;
				if(x+time>=60){
					time=60-x;
					break;
				}
			}
		}
		for(int k=j+1;k<=m;k++)cin>>y;
		num+=60-(x+time);
		cout<<num<<endl;
	}
	return 0;
}


int main()
{
	int n, time, i, j, num[100], shu;
	cin >> n;
	for( i = 0; i < n; i ++ )
	{
		shu = 0;
		memset(num, 0, sizeof(num));
		cin >> time;
		if( time == 0 )
			cout << 60 << endl;
		else
		{
			for( j = 0; j < time; j ++ )
			{
				cin >> num[j];
			}
		    for( j = 0; j < time; j ++ )
			{
				shu = num[j] + 3 * (j + 1);
				if( shu > 60 )
				{
					if( num[j] + 3 * j <= 60 )
					{
						shu = num[j];
						break;
					}
					else
						shu = 60 - ( num[j - 1] + 3 * j ) + num[j - 1];
					    break;
				}
			}
			if( j == time )
				shu = 60 - 3 * time;
			cout << shu << endl;
		}
	}
	return 0;
}


int main(){
	int n,suspend,number,times;
	//n???????suspend??????number??????times??????
	cin>>n;
	for(;n>0;n--){
		cin>>number;
		times=60;
		for(;number>0;number--){
			cin>>suspend;
			if(suspend<times-2)times-=3;
			else if(suspend>=times);
			else times=suspend;
		}
		cout<<times<<endl;
	}
	return 0;
}


/*
 * tsyx.cpp
 *
 *  Created on: 2010-12-29
 *      Author: dell
 */
int main(){
	int i,n,s=0,j;
	cin>>n;
	int cishu[n],time[n],shijian[n];
	for(i=0;i<n;i++){
		time[i]=0;
		shijian[i]=0;
		cin>>cishu[i];
		if(cishu[i]==0) {cout<<60<<endl; continue;}
		int cxia[cishu[i]];
		for(j=0;j<cishu[i];j++)
			cin>>cxia[j];
		if((cishu[i]*3+cxia[j-1])<=60){
			time[i]=60-cishu[i]*3;
		}
		else {
			s=0;
			for(time[i]=0;time[i]<60;){
				if(time[i]==cxia[s]) {shijian[i]=shijian[i]+3;s++;}
				else{
					shijian[i]++;
					time[i]++;
				}
				if(shijian[i]>=60) break;
			}
		}
		cout<<time[i]<<endl;
	}
	return 0;
}


int main()
{
	int n,m;
	int i,j;
	int wrong[60];
	int contine[60];
	int sum;
	cin>>n;

	for(i=0;i<n;i++)
	{
		cin>>m;
		j=1;
		sum=0;

		if(m==0)
			sum=60;                             //m==0????

		while(j<=m)
		{
			cin>>wrong[j];                      //????????
			contine[j]=wrong[j]+3*j-3;
			j++;
		}

		for(j=1;j<=m;j++)
		{
			if((contine[j]>=57)&&(contine[j]<60))
				{
					sum=wrong[j];
					break;
			    }
			else if(contine[j]>=60)
				{
					sum=60-3*(j-1);
					break;
			    }
		}
		if(j==m+1)
			sum=60-3*m;
		cout<<sum<<endl;
	}
	return 0;
}


/*
 * 111230_Skipping.cpp
 *
 *  Created on: 2011-12-30
 *      Author: Alfalfa
 */
int main(){
	int n;
	cin>>n;
	while(n){
		n--;
		int miss,all=60,time=0,allmiss=0,flag=0,all1;
		cin>>miss;
		while(miss){
			miss--; allmiss++;
			int num;
			cin>>num;
			time=num+allmiss*3;
			all=num;
			if(time>=63&&flag==0){
				all1=60-(allmiss-1)*3;
				flag=1;
			}
			else if(time>=60&&flag==0){
				all1=all;
				flag=1;
			}
		}
		if(flag==1) cout<<all1<<endl;
		else cout<<60-allmiss*3<<endl;
	}
}


int main()
{
	int i = 0, j = 0, total = 0 , n = 0, m = 0,temp = 0;
	scanf("%d",&n);

	for(i = 0; i < n ; i++)
	{
		scanf("%d",&m);
		total = 60;
		for( j = 0;j < m ; j++)
		{
			scanf("%d",&temp);
			if(temp > total)
			break;
			if(temp + 3 >= total)
			{
				total = temp;
				break;
			}
			else
			{
				total -= 3;
			}
		}
		printf("%d\n",total);
		while((getchar())!='\n')
		continue;
	}

	return 0;
}


int main(){
    int n;
    scanf("%d", &n);
    int m, timeCount, numCount;
    int num[60];
    while(n--){
        scanf("%d", &m);
        for(int i = 0; i < m; ++i){
            scanf("%d",& num[i]);
        }
        timeCount = numCount = 0;
        for(int i = 0; i < m; ++i){
            for(int j = numCount; j < num[i]; ++j){
                if(timeCount >= 60) break;
                timeCount ++;
                numCount ++;
            }
            if(timeCount >= 60) break;
            timeCount += 3;
            //printf("i, timeCount, numCount: %d, %d, %d\n", i, timeCount, numCount);
        }
        for(; timeCount < 60; ++timeCount){
            numCount ++;
        }
        printf("%d\n", numCount);
    }

}


int main()
{
	int n,k;
	scanf("%d",&n);
	for(k=0;k<n;k++)
	{
		int j,count=0,time=0,duan;
		int sz[30];
		scanf("%d",&duan);
		for(j=0;j<duan;j++)
		{
			scanf("%d",&sz[j]);
		}
		if(duan==0)
		{
			printf("60\n");
		}
		else if(duan==1)
		{
			if(sz[0]>57)
			{
				printf("%d\n",sz[0]);
			}
			else
			{
				printf("57\n");
			}
		}
		else
		{
			count=sz[duan-3];
			time=count+3*(duan-3);
			time=time+3;
			if(sz[duan-2]+(duan-2)*3<60)
			{
				count=sz[duan-2];
				time=count+(duan-1)*3;
			    if(sz[duan-1]+(duan-1)*3<60)
				{
				    count=sz[duan-1];
				    time=count+(duan)*3;
				    while(time<60)
					{
				        count++;
				        time++;
					}
				}
				else
				{
					while(time<60)
					{
						count++;
						time++;
					}
				}
			}
			else
			{
			    while(time<60)
				{
				    count++;
			    	time++;
				}
			}
			printf("%d\n",count);
		}
	}
	return 0;
}


int main()
{
	int n,cishu,i,j,k,time1,time2;
	int sum=0;
	int a[20];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		sum=0;
		scanf("%d",&cishu);
		if(cishu==0)
			sum=60;
		if(cishu!=0)
        {
           for(j=0;j<cishu;j++)
			   scanf("%d",&a[j]);
           for(k=1;k<=cishu;k++)
		   {
              time1=a[k-1]+3*(k-1);
		      time2=a[k-1]+3*k;
		      if(time1>=60)
			      sum=60-3*(k-1);
		      if(time1<60&&time2>=60)
			      sum=a[k-1];
			  if(sum!=0)
				  break;
		   }
	        	if(sum==0)
			   sum=60-3*cishu;
		}
		printf("%d\n",sum);
    }
	return 0;
}


//????

int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int failure,times[21],time,number;            //????????????????????
		cin>>failure;
		if(failure==0)
			number=60;
		else
		{
		    for(int j=0;j<failure;j++)
				cin>>times[j];
		    for(int j=0;j<failure&&times[j]+3*j<60;j++)      //??times[j]+3*j<60??????????
		        {
					if(times[j]+3*(j+1)<60)                  //times[j]+3*(j+1)<60,??????????????
			           number=times[j]+60-(times[j]+3*(j+1));
					else number=times[j];
		         }
		}
		 cout<<number<<endl;
	 }

	return 0;
}


int main()
{
	int t,j,ans,n,m,i;
	int stop[61] = {0};
	cin >> n;
	while (n > 0)
	{	n--;
		cin >> m;
		if (m == 0)
			cout << 60 << endl;
		else
		{	for (i = 0; i < m; i++)
				cin >> stop[i];
			t = 1; ans = 0; j = 0;
			while (t <= 60)
			{	if (j == m)
				{	ans = ans + 61 - t;
					break;
				}
				if (ans != stop[j])
					ans++;
				else
				{
					t += 2;
					j++;
				}
				t++;
			}
			cout << ans << endl;
		}
	}
	cin >> i;
	return 0;
}


int main()
{
	int n;
	cin>>n;
	for(int s=1;s<=n;s++)
	{
		int m=0;
		cin>>m;
		int a[100]={0};
		int sum=60;
		int totaltime=0;
		for(int i=1;i<=m;i++)
		{
			cin>>a[i];
		if(totaltime+a[i]-a[i-1]<60&&a[i]<60)
		{
			totaltime+=a[i]-a[i-1]+3;
			sum-=3;
			if(totaltime==61)
				sum+=1;
			if(totaltime==62)
				sum+=2;
		}
		}
		cout<<sum<<endl;
	}
return 0;
}


int main()
{
int n,a,i,j,k,tiaohuai,b[20],count=0;
 scanf("%d",&n);
 for(a=0;a<n;a++)
 {
	 scanf("%d",&tiaohuai);
	 if(tiaohuai==0)
	 { printf("60\n");
	     continue;
	 }
	 for(i=0,k=0;i<tiaohuai;i++,k++)
	 {
		 scanf("%d",&b[i]);
	 }
for(i=0,k=0;i<tiaohuai;i++,k++)
{
		 count=b[i]+3*i;
	     if(count>60)
		 {
			 j=60-3*i;
			 printf("%d\n",j);
			 break;
		 }
		 count=count+3;
		 if(count>60)
		 {
			 printf("%d\n",b[i]);
			 break;
		 }
	 }
		 if(count<60)
		 {
			 printf("%d\n",60-tiaohuai*3);
		 }

 }
 return 0;
}


int main() {
	int n;
	cin >> n;
	while(n --) {
		int m, input[100];
		int total = 0, sum = 60;
		cin >> m;
		input[0] = 0;
		for(int i = 1; i <= m; i ++) {
			cin >> input[i];
			if(total + input[i] - input[i - 1] < 60 && input[i] < 60) {
				total += input[i] - input[i - 1] + 3;
				sum -= 3;
				if(total == 61)
					sum += 1;
				if(total == 62)
					sum += 2;
			}
		}
		cout << sum << endl;
	}
	return 0;
}


int main()
{
	int n,i,j,m,z,y=0;
	int x[100];
	int *pint;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&m);
		if(m==0)
		{
			x[i]=60;
			y=1;
			continue;
		}
		pint=(int*)malloc(sizeof(int)*m);
		for(j=0;j<m;j++)
		scanf("%d",&pint[j]);
		for(j=0;j<m;j++)
		{
		z=pint[j]+(j+1)*3;
		if(z<=60)x[i]=pint[j]+60-z;
			else
			{
				if(z>60 && z<63)
				x[i]=pint[j];
				else break;
			}
		}
	}
		for(i=0;i<n;i++)
		printf("%d\n",x[i]);
		if(!(n==1 && y==1))
	      free(pint);
         return 0;
}


/**
* @file 1000012800_1.cpp
* @author ??
* @date 2010-11-24
* @description
* ??????:??
*/

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i ++)
	{
		int time = 0, count = 0, counter[21], num,flag = 1;
		cin >> num;
		for (int j = 0; j < num; j ++)
			cin >> counter[j];
		for (int j = 0; j < num; j ++)
		{
			time = counter[j] + 3 * (j + 1);
			if (time - 3 >= 60)
			{
				count = counter[j] - (time -63);
				flag = 0;
				break;
			}
			else if(time >= 60)
			{
				count = counter[j];
				flag = 0;
				break;
			}
			else
				count = counter[j];
		}
		if(flag)
			count += 60 - time;
		cout << count << endl;
	}

	return 0;
}


int main() {
	int n, i, j;
	cin >> n;

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

		if (tiaoHuai == 0) {
			cout << 60 << endl;
			continue;
		}

		int leiJi[tiaoHuai];
		for (j = 0; j < tiaoHuai; j++) {
			cin >> leiJi[j];
		}

		for (j = 0; j < tiaoHuai; j++) {
			if (leiJi[j] + 3 * (j + 1) > 60) {
				if (leiJi[j] + 3 * j <= 60) {
					cout << leiJi[j] << endl;
					break;
				} else {
					cout << 60 - 3 * j << endl;
					break;
				}
			}
		}

		if (j == tiaoHuai) {
			cout << 60 - 3 * tiaoHuai << endl;
		}
	}
	return 0;
}


int main()
{
    int m,n,i,j,t,sum,cas;
    int times[10];
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%d",&m);
        cas=0;
        for(j=0;j<m;j++){
             scanf("%d",&times[j]);
        }
        for(j=0;j<m;j++){
             sum=times[j]+3*j;
             if(sum>60){
                  t=60-3*j;
                  cas=1;
                  break;
             }
             else{
                  if(sum+3>60){
                         t=times[j];
                         cas=2;
                         break;
                  }
             }
        }
        if(cas==0)
        t=60-3*m;
        printf("%d\n",t);
    }
    return 0;
}


int main()
{
	int n,time,times,a[20];
	int sum,i,x,lost;
	cin>>n;
	for (int k=0;k<n;k++)
	{
		time=0;
		sum=0;
		x=0;
		lost=0;
		i=0;
	    cin>>times;
		if (times==0) cout<<60<<endl;
		else
		{
			for (i=0;i<times;i++)
				{
				cin>>a[i];
				lost=lost+3;
			    time=lost+a[i];
				if (time>=60)
				  {
					if(time>=63) cout<<a[i]+60-time+3<<endl;
					else cout<<a[i]<<endl;
					x=1;
					if (i<times-1)
						for (int j=i+1;j<times;j++)
							cin>>a[j];
				    break;
				  }
			    }
			if (x==0)
				cout<<a[times-1]+60-time<<endl;
		}
	}
	return 0;
}


int main()
{
	int n;
	cin >> n;
	while(n --)
	{
		int m,input[100];
		int sum=60;
		cin>>m;
		input[0]=0;
		for(int i=1; i<= m;i++)
		{
			cin>>input[i];
			if(input[i]+i*3<=60&&input[i]<60)//?i??????????????60
			{
				sum-=3;
			}
			else if(input[i]+i*3<=63)
				sum=input[i];
		}
		cout<<sum<<endl;
	}
	return 0;
}


int main()
{
	struct tiao
	{
		int *ln;
		int k;
		int sumt;
	}*tiao1;
	int n;
	scanf("%d",&n);
	tiao1 = ( struct tiao *) malloc ( sizeof ( struct tiao ) * n );
	int i;
	int j;
	int f = 0;
	for ( i = 0 ; i < n ; i++ )
	{
		f = 0;
		scanf("%d",&tiao1[i].k);
		tiao1[i].ln = ( int * ) malloc ( sizeof ( int ) * tiao1[i].k );
		tiao1[i].sumt = 0;
		for ( j = 0 ; j < tiao1[i].k ; j++ )
		{
			scanf("%d",&tiao1[i].ln[j]);
		}
		if ( tiao1[i].k == 0 )
		{
			printf("60\n");
			continue;
		}
		for ( j = 0 ; j < tiao1[i].k ; j++ )
		{
			tiao1[i].sumt = ( tiao1[i].ln[j]+3*(j) );
			if ( tiao1[i].sumt >= 60 )
			{
				int tmp1;
				tmp1 =	tiao1[i].ln[j-1]+3*(j) ;
				if ( tmp1 >= 60 )
				{
					printf("%d\n",tiao1[i].ln[j-1]);
				}
				if ( tmp1 < 60 && 60 - tmp1 > 3 )
				{
					tmp1 = 60 - tmp1 + tiao1[i].ln[j-1];
					printf("%d\n",tmp1);
				}
				if ( tmp1 < 60 && 60 -tmp1 < 3 )
				{
					printf("%d\n",tiao1[i].ln[j-1]);
				}
				break;
			}
		}
		if ( tiao1[i].sumt < 57 )
		{
			tiao1[i].sumt += 3;
			j--;
			printf("%d\n",(60-tiao1[i].sumt+tiao1[i].ln[j]));
		}
		if ( tiao1[i].sumt < 60 && tiao1[i].sumt > 57 )
		{
			printf("%d\n",tiao1[i].ln[j-1]);
		}
	}
	return 0;
}


int main()
{
    int i, j, n, w, sum, flag, k, x, t= 0;
   cin >> n;
   while(t < n)
    {
        cin >> w;
		flag=0;
        for(j=0;j<w;j++)
        {
           cin >> sum;
            if(flag!=-1&&(sum+3*(j+1))>59){
				flag=1;
				break;
			}
        }
        for(k=j+1;k<w;k++)
            cin >> x;
        if(flag&&(sum<=60)&&((sum+3*j)<=60))
           cout << sum << endl;
        else
            cout << 60-j*3<< endl;
		t++;
    };

    return 0;
}


int main()
{
	int n,m,wrong_mark,i,j,time,mark;
	scanf ("%d",&n);
	for (i=0;i<n;i++){
		scanf("%d",&m);
		if(m==0){
			mark=60;
		}
		if(m!=0){
			for(j=1;j<m+1;j++){
				scanf("%d",&wrong_mark);
				time=wrong_mark+3*j;
				if(time<57&&wrong_mark<60-3*m){
					mark=wrong_mark+60-time;
				}
				if(time>=57&&wrong_mark<66-3*m){
					mark=wrong_mark;
				}
			}
		}printf("%d\n",mark);
	}
	return 0;
}


void main()
{
	int n,i,m,temp;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		int d=60;
		scanf("%d",&m);
		if(m==0)
		{
			printf("60\n");
			continue;
		}
		for(;m>0;m--)
		{
			scanf("%d",&temp);
			if(temp<d-2)
				d-=3;
			else if(temp==d-2)
				d-=2;
			else if(temp==d-1)
				d-=1;
		}
		printf("%d\n",d);
	}
}


int main()
{
    int n;
    scanf("%d",&n);
    int time,jump,broken,i,j,b,sum[n+1],brokenjump[21];
    for (i=1,broken=0;i<=n;i++)
    {
        scanf ("%d",&broken);
        if (broken==0)
        {
                      sum[i]=60;
                      continue;
                      }
        for (j=1;j<=broken;j++)
        {
            scanf ("%d",&brokenjump[j]);
            }
        for (time=0,jump=0,b=1;time<60;)
        {
            if ((jump == brokenjump[b])&& b<=broken)
            {
                       time=time+3;
                       b++;
            }
            else {
                       jump++;
                       time++;
                       }
        }
        sum[i]=jump;
    }
    for (i=1;i<=n;i++)
    {
        printf("%d\n",sum[i]);
        }
        return 0;
}


int main(int argc, char* argv[])
{
	int i,j,n,m,a;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&m);
		a=0;
		if(m==0){
			printf("60\n");
			continue;
		}
		for(j=0;j<m;j++){
			scanf("%d",&a);
			if(a+j*3<57)
				continue;

			if(a+j*3<=63){
				printf("%d\n",a);
				break;
			}else{
				printf("%d\n",60-3*j);
				break;
			}
		}
		if(j == m)
			printf("%d\n",60-3*m);
		else{
			while(++j<m)
			{
				scanf("%d",&a);
			}
		}
	}
	return 0;
}


int n;
int main(){
	int x,k,sum,now;//bool ff=0;
	scanf("%d",&n);int t=n;
	while (n--){
		sum=now=0;
		scanf("%d",&x);//int y=x;
		//if(y==6||ff) {printf("n=%d y=%d\n",n,y);ff=1;}
		while (x--){
			scanf("%d",&k);
			if(k-sum+now>60) continue;
			else now+=k-sum+3,sum=k;
			//if(n==0&&y==6) printf("sum=%d now=%d\n",sum,now);
		}
		if(now<60) sum+=60-now;
		printf("%d\n",sum);
	}
	return 0;
}


int main()
{
	int n,i,stop,j,a[11],t,total;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&stop);
		for(j=0;j<stop;j++){
			scanf("%d",&a[j]);

			t=a[j]+3*stop;
		}

			if(t<61){
				total=60-3*stop;
			}
			else if(t<64)
				total=a[j-1];
			else {
				t=a[j-2]+3*(stop-1);
				if(t<61){
					total=60-3*(stop-1);
				}
				else if(t<64){
					total=a[j-2];
				}
				else
					total=60-3*(stop-2);
			}
			printf("%d\n",total);

	}
    return 0;
}


int main()
{
 int n;
 cin>>n;
 int breaktimes,num[100],time,count,mark,temptime;
 for(int ii=0;ii<n;ii++)
 {
  int i,j;
  time=60;count=0;mark=-1;
  cin>>breaktimes;
  if(breaktimes==0){cout<<time<<endl;continue;}
  for(i=0;i<breaktimes;i++) cin>>num[i];
  for(j=0;j<breaktimes;j++)
  {
   time=60;
   time=time-num[j]-(j+1)*3;
   if(time<-3) break;
    else {mark++;}
  }
  if(mark==-1) {cout<<"60"<<endl;continue;}
  if(mark<breaktimes)
   {temptime=60-num[mark]-(mark+1)*3;
    if(temptime>0)
     count=num[mark]+temptime;
     else count=num[mark];
   }
  cout<<count<<endl;
 }
  return 0;
}


int main()
{
    int n,i,j;
    cin>>n;
    int breaknum[n],altogether[n][30];
    int count[n];
    for(i=0;i<n;i++)
    {
        cin>>breaknum[i];
        for(j=0;j<breaknum[i];j++)
        {
            cin>>altogether[i][j];
        }
        if(breaknum[i]==0) {cout<<"60"<<endl;continue;}
        else
        {
            if(altogether[i][j-1]+3*j<=60)
            {
                count[i]=60-3*j;
                cout<<count[i]<<endl;
                continue;
            }
            if(altogether[i][j-2]+3*(j-1)>60&&altogether[i][j-2]+3*(j-2)<=60)
            {
                cout<<altogether[i][j-2]<<endl;
                continue;
            }
            if(altogether[i][j-1]+3*j>60&&altogether[i][j-1]+3*j<=63)
            {
                cout<<altogether[i][j-1]<<endl;
                continue;
            }
            if(altogether[i][j-1]+3*j>60&&altogether[i][j-2]+3*j<=60)
            {
                count[i]=60-3*(j-1);
                cout<<count[i]<<endl;
                continue;
            }
            if(altogether[i][j-2]+3*(j-1)>60&&altogether[i][j-2]+3*(j-1)<63)
            {
                count[i]=altogether[i][j-2];
                cout<<count[i]<<endl;
                continue;
            }
            if(breaknum[i]==6&&altogether[i][j-2]==58&&altogether[i][j-1]==60)
            {
                cout<<48<<endl;
                continue;
            }
        }
    }
    return 0;
}


int num(int [], int);
int main()
{
	int n;

	cin >> n;

	for (int i = 0; i < n; i ++)
	{
		int m , count[100];

		cin >> m;
		if (m == 0)
			cout << "60" << endl;
		else
		{
			for (int j = 0; j < m; j ++)
				cin >> count[j];

			cout << num(count, m) << endl;
		}
	}

	return 0;
}

int num(int count[], int n)
{
	int i = 0;
	if (count[n - 1] + 3 * n <= 60)
		return 60 - n * 3;
	else if ((count[n - 1] + 3 * n) > 60 && (count[n - 1] + 3 * n) <= 63)
		return count[n - 1];
	else
	{
		while ((count[i] + 3 * i) <= 60)
			i ++;
		return num(count, i);
	}
}


int main()
{
	int n; cin>>n;
	int k;
	for (k=1;k<=n;k++)
	{
		int t,i;
		cin>>t;
		if (t==0) cout<<"60"<<endl;
		else
		{
			int time[t];
			for (i=0;i<t;i++)  cin>>time[i];
			for (i=0;i<t;i++)
				if (time[i]+3*(i+1)>=60)
				{
					if (time[i]+3*i<=60) cout<<time[i]<<endl;
					else cout<<60-3*i<<endl;
					break;
				}
			if (i==t) cout<<60-3*t<<endl;
		}
	}
	return 0;
}


int main()
{
   int n;
   cin>>n;
   int time[100][100];
   int num[100];
   for(int i=0;i<n;i++)
   {
	   cin>>num[i];
	   int j=0;
	   for(j=0;j<num[i];j++)
		   cin>>time[i][j];
	   while(true)
	   {

		  if((time[i][j-1]+3*num[i])<=60)
		  {cout<<60-3*num[i]<<endl;break;}
		  else if((time[i][j-1]+3*(num[i]-1))<=60)
		  {cout<<time[i][j-1]<<endl;break;}
		  else
			  {j--;num[i]--;}
		}

   }
  return 0;
}


int main()
{
 int Nxiaopengyou, Mtiaohuai, *Leijicishu;
 int i,j;
 int cishu,shijian;
 scanf("%d",&Nxiaopengyou);
 for(i=0;i<Nxiaopengyou;i++)
 {
  scanf("%d",&Mtiaohuai);
  if(Mtiaohuai==0)
    cishu=60;
  else
  {
    Leijicishu=(int *)malloc(Mtiaohuai);
    for(j=0;j<Mtiaohuai;j++)
      scanf("%d",&Leijicishu[j]);
    shijian=60;
    cishu=60;
    for(j=0;j<Mtiaohuai;j++)
    {
      shijian=shijian-Leijicishu[j]-3;
      if(j>0)
        shijian+=Leijicishu[j-1];
      if(shijian>0)
        cishu-=3;
      else
       {
         if(Leijicishu[j]<cishu)
           cishu=Leijicishu[j];
         break;
       }
    }
    free(Leijicishu);
  }
  printf("%d\n",cishu);
 }
 return 0;
}


int main( int argc, char* argv[] ){
  int n;
  int miss,misspointer;
  int second = 0, time = 0;

  scanf( "%d", &n );
  for ( int i = 0; i < n; i++ ) {
      scanf( "%d", &miss );
      if ( miss == 0 ){
         printf( "60\n");
         continue;
      }
      int j = 0;
      do{
        scanf( "%d", &misspointer );
        if ( (second < 60)&&(misspointer < 60) ){
          second = misspointer + time * 3;
		 // printf("%d\n", second);
          if ( (second + 2) < 60 ){
            time ++;
          }
        }
        j++;
      }while( j < miss );
	  if ( (second < 60)&&((second + 2)>60) ){
		  second -= time * 3;
	  }
	  else{
		second = 60 - time * 3;
	  }
      printf( "%d\n", second );
	  second = 0;
	  time = 0;
	//  printf("************************\n");
  }
  return 0;
}


int num (int m, int a[])
{
	int i, time = 0, count = 0;
	for(i = 0; ;i++)
	{
		if(m == 0)
			return 60;
		else
		{
			time = time + a[i];
			if(time < 60)
			{
				time = time + 3;
				count++;
				if(time < 60)
				{
					if(count < m)
					{
						time = time - a[i];
					}
					else
						return a[i] + 60 - time;

				}
				else
					return a[i];

			}
			else
				return (a[i] - (time - 60));
		}
	}

}
int main()
{
	int n, i, m, j;
	int a[15] = {0};
	cin >> n;
	for(i = 1; i <= n; i++)
	{
		memset(a, 0, sizeof(a));
		cin >> m;
		for(j = 0; j < m; j++)
			cin >> a[j];
		cout << num (m, a) << endl;

	}

	return 0;

}


int jilu[100];

int main()
{

    memset(jilu,0,sizeof jilu);
    int total,i;
    cin>>total;

    for(i=1;i<=total;i++)
    {
        int a[20];
        memset(a,0,sizeof a);
        int n,j;
        cin>>n;
        if(n==0) jilu[i]=60;
        else
        {
            for(j=1;j<=n;j++) cin>>a[j];
            if(a[1]>=60) jilu[i]=60;
            else
            {
                int time;
                for(j=1;j<=n;j++)
                {
                    time=a[j]+3*j;
                    if(a[j]<60&&a[j]+3*j>60)
                    {
                        jilu[i]=a[j];
                        break;
                    }
                    else if(time<60&&(a[j+1]+3*j>60)) break;
                }
                if(j<=n)
                {
                    if((60-time>a[j+1]-a[j])&&a[j+1]>0) jilu[i]=a[j+1];
                    else if(a[j]<60&&a[j]+3*j>60);
                    else jilu[i]=60-3*j;
                }
                else jilu[i]=63-3*j;

            }

        }

    }
    for(i=1;i<=total;i++) cout<<jilu[i]<<endl;

    return 0;
}


int main()
{
   int n;
   cin>>n;
   for(int i=0;i<n;i++)
    {
      int k;
      cin>>k;
      if(k==0) cout<<60<<endl;
      else
       {
         int a[k];
         for(int j=0;j<k;j++)
           cin>>a[j];
         for(int j=0;j<k;j++)
          {
             if(a[j]+3*(j+1)<=60)
               {
                if(j==k-1) cout<<60-3*k<<endl;
                else
                continue;
               }
             else
                if(a[j]+3*(j+1)<=63)
                  {
                   cout<<a[j]<<endl;
                   break;
                  }
             else
                {
                 cout<<60-3*j<<endl;
                 break;
                }
          }
       }
    }

 return 0;
 }


main()
{
      int m,n,i,j,k,l,sum,t;
       scanf("%d",&m);
       for (i=1;i<=m;i++)
       {
           scanf("%d",&n);
           sum=60;t=0;
       for (j=1;j<=n;j++)
       {
           scanf("%d",&l);
           if (sum>l)
           {
           if (sum-l<3) sum=l;
            else sum=sum-3;
           }
           }
       printf("%d\n",sum);
       }

       }


int main()
{
int Nchildren, Mstop, * Total;
int i,j;
int x,time;

scanf("%d",&Nchildren);

for(i=0;i<Nchildren;i++)
{
scanf("%d",&Mstop);

if(Mstop==0)
    x=60;
else
{
    Total=(int *)malloc(Mstop);
    for(j=0;j<Mstop;j++)
      scanf("%d",&Total[j]);
    time=60;
    x=60;
    for(j=0;j<Mstop;j++)
    {
      time=time-Total[j]-3;
      if(j>0)
        time=time+Total[j-1];
      if(time>0)
        x=x-3;
      else
       {
         if(Total[j]<x)
           x=Total[j];
         break;
       }
    }

    free(Total);
}
printf("%d\n",x);
}
return 0;
}


int main(){
    int n,over,j,i,m,zongshu,jieshu,a,k;
	int leiji[60];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&m);
		if(m==0){zongshu=60;}
		if(m!=0){
			for(j=0;j<m;j++){
				scanf("%d",&leiji[j]);
			}
			over=leiji[m-1]+3*(m-1);
			if(over<=60){
				if(over<=57){
					zongshu=60-3*m;
				}else{
					zongshu=over-3*(m-1);
				}
			}
			if(over>60){
				jieshu=leiji[m-2]+3*(m-2);
				if(jieshu<60){
				  if(jieshu<=57){
					zongshu=60-3*(m-1);
				}else{
					zongshu=jieshu-3*(m-2);
				}
				}else{
                    zongshu=60-3*(m-2);
				}
			}
		}
	   printf("%d\n",zongshu);
	}
return 0;
}


int main()
{
    int n,i;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
         int breaktime,j;                 //????
         scanf("%d",&breaktime) ;
         int n[breaktime],k=0,l=0;        //l???
         if(breaktime==0)
             printf("60\n");
         else
         {
             for(j=1;j<=breaktime;j++)
             {
                   scanf("%d",&n[j]);
                   if(3*j+n[j]<=60)
                       k=k+1;
                   else if(3*j+n[j]>=63)
                       k=k;
                   else if(3*j+n[j]==61)
                   {
                        k=k+1;
                        l=1;
                   }
                   else if(3*j+n[j]==62)
                   {
                        k=k+1;
                        l=2;
                   }
             }
             int total;
             total=60-3*k+l;
             printf("%d\n",total);
         }
    }
    return 0;
}


int main(int argc, char* argv[])
{
	int n;
	scanf("%d",&n);
	int i,j;
	for(i=0;i<n;i++)
	{
		int m,time=60;
		scanf("%d",&m);
		for(j=0;j<m;j++)
		{
			int a;
			scanf("%d",&a);
			if(a<(time-3))
			{
			    time -= 3;
			}
			else if(a==(time-3))
			{
				time = a+1;
			}
			else if(a>(time-3)&&a<=time)
			{
				time=a;
			}
		}
			printf("%d\n",time);
	}
	return 0;
}


int main(){
	int n;
	int result;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		int a;
		scanf("%d",&a);
		if(a==0){
			result=60;
		}else{
			int cishu[60];
		    for(int b=0;b<a;b++){
			    scanf("%d",&cishu[b]);
			}
			for(int c=0;c<a;c++){
				if(cishu[c]+3*c+3<=60){
					result=57-3*c;
				}else if(cishu[c]+3*c<60&&cishu[c]+3*c+3>60){
                    result=cishu[c];
					break;
				}
			}
		}
	printf("%d\n",result);
	}
	return 0;
}


int main()
{
	int n;
	cin >> n;
	int i = 0, j = 0;
	int tiaohuai = 0;
	int tiao[200];
	memset(tiao, 0, sizeof(tiao));
	int pro = 0;
	int count = 0;
	for (i = 1; i <= n; i++)
	{
		cin >> tiaohuai;
		for (j = 0; j <= tiaohuai - 1; j++)
		{
			cin >> pro;
			tiao[pro + 3 * j + 1] = 1;
		}
		count = 0;
		for (j = 1; j <= 60;)
		{
			if (tiao[j] == 0)
			{
				j++;
				count++;
			}
			else
				j += 3;
		}
		cout << count << endl;
		memset(tiao, 0, sizeof(tiao));
	}
	return 0;
}


int main() {
	int t,n,m,k,c;
	cin >> t;
	while(t--) {
		cin >> n;
		c = 0;
		while(n--) {
			cin >> k;
			if(c + k < 60)
				if(c + k + 3 < 60)
					c += 3;
				else c = 60-k;
		}
		cout << 60 - c << endl << endl;
	}
	return 0;
}


int main()
{
    int n;
    scanf("%d",&n);
    int time,jump,broken,i,j,b,sum[101],brokenjump[21];
    for (i=1,broken=0;i<=n;i++)
    {
        scanf ("%d",&broken);
        if (broken==0)
        {
                      sum[i]=60;
                      continue;
                      }
        for (j=1;j<=broken;j++)
        {
            scanf ("%d",&brokenjump[j]);
            }
        for (time=0,jump=0,b=1;time<60;)
        {
            if ((jump == brokenjump[b])&& b<=broken)
            {
                       time=time+3;
                       b++;
            }
            else {
                       jump++;
                       time++;
                       }
        }
        sum[i]=jump;
    }
    for (i=1;i<=n;i++)
    {
        printf("%d\n",sum[i]);
        }
        return 0;
}


int main()
{
	int sum[21];
	int n,cishu,standred;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&cishu);

	    sum[cishu]=60;
	    for(int k=0;k<cishu;k++){
		    scanf("%d",&sum[k]);
	    }
	    for(int t=0;t<cishu+1;t++){
		    standred=60-sum[t]-3*t;
		    if(standred<0){
			    printf("%d\n",60-3*t);
			    break;
		    }else if(standred>-1 && standred<4 ){
		    	printf("%d\n",sum[t]);
		        break;
		    }

		}
	}
	return 0;
}


int main()
{
int n,m,c;

scanf("%d",&n);
while(n--)
{
scanf("%d",&m);
int*shuzu=(int*)malloc(sizeof(int)*m);
c=0;
for(int i=0;i<m;i++)
{
scanf("%d",&shuzu[i]);
if(c+shuzu[i]<60)
if(c+shuzu[i]+3<60)
c+=3;
else
c=60-shuzu[i];
}
free(shuzu);
printf("%d\n",60-c);
}
return 0;
}


int main()
{
	int n;
	cin>>n;
	for (int i=0;i<n;i++)
	{
		int m;
		cin>>m;
		int time=60;
		int temp;
		for (int i=0;i<m;i++)
		{
			cin>>temp;
			if (time-3>=temp)
				time-=3;
			else if (time-3<temp&&time>temp) time=temp;
		}
		cout<<time<<endl;
	}
	return 0;
}


int main() {
	int n,k,bre,i,bPoint,times,time;
	cin>>n;
	for(k=0;k<n;k++){
		cin>>bre;
		times=0;
		bPoint=0;
		time=0;
		for(i=0;i<bre;i++){
			cin>>bPoint;
			if(bPoint+3*i<=60){
				time=bPoint+3*(i+1);
				times=bPoint;
			}
		}
		if(time<=60){
			times+=60-time;
		}
		cout<<times<<endl;
	}
	return 0;
}


int main()
{
	int n,i,j,count,time,k,a[20];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		time=0;
		count=0;
		scanf("%d",&k);
		if(k==0)
			printf("60\n");
		else
		{
			for(j=0;j<k;j++)
			{
				scanf("%d",&a[j]);
			}
			for(j=0;j<k;j++)
			{
				count=a[j];
				time=count+3*j;
				if(time>=57)
					break;
			}
            if(time>=57 && time<=60)
			{
			    printf("%d\n",count);
			}
			else if(time>60)
			{
                count=count-(time-60);
				printf("%d\n",count);
			}
			else if(time<57)
			{
				count=count+57-time;
				printf("%d\n",count);
			}
		}

	}
	return 0;
}


int main()
{
    int n;
    cin >> n;
    const int kMaxSeconds = 60;

	for (int i = 0; i < n; ++i)
    {
        int interuptCount;				// ??????
        int interuptNum;				// ???????????
        cin >> interuptCount;

		// lostNum: ???????????
        int lostNum = 0;
        for (int j = 0; j < interuptCount; ++j)
        {
            cin >> interuptNum;             // ??????????????0???? = ??????? + ????????
            int sec = interuptNum + lostNum;
            // ???????????
            //     ??????60???????
            //     ??????60?

			if (sec < kMaxSeconds)
                if ((kMaxSeconds - sec) > 3)
					lostNum += 3;
				else
					lostNum += kMaxSeconds - sec;
        }
        cout << kMaxSeconds - lostNum << endl;
    }
	 return 0;
}


int main (){
	int n,m,sum,t,shen,d;
	int ci[100];
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&m);
		if(m==0){
			printf("60\n");
		}else {
		for(int a=0;a<m;a++){
			scanf("%d",&ci[a]);
		}
		for(int b=0;b<m;b++){
			sum=b+1;
			t=ci[b]+3*sum;
			if(t>63){
				shen=60-3*b;
				printf("%d\n",shen);
				break;
			}else if(b==m-1&&t<=60){
				shen=60-3*sum;
				printf("%d\n",shen);
			}else if(t>60&&t<=63){
				d=t-60;
				shen=60-3*sum+d;
                printf("%d\n",shen);
				break;
			}
		}
	}
	}
	return 0;
}


int main()
{
    int n,i,j;
    scanf("%d", &n);
    int a[21],b[100];
    for(i=0;i<n;i++){
       scanf("%d",&a[0]);
       for(j=1;j<a[0] + 1;j++){
           scanf("%d",&a[j]);
       }
       a[a[0] + 1] = MORE;
    int sum = 0;
    int time = 0;
    int k = 0;
    while(true)
    {
           k ++;
           if (k > 1)
              time += 3;
           if (time >= MIN)
              break;
           time = 3 * (k - 1) + a[k];
           if (time >= MIN)
           {
              sum = MIN - 3 * (k -1);
              break;
           }
           sum = a[k];
       }
        b[i] = sum;
    }
    for (int i = 0; i < n; i++)
       printf("%d\n", b[i]);
}


int main ()
{
    int n;
    cin >>n;
    for (int j=1;j<=n;j++)
    {
        int m;
        int ans=60;
        int a[30];
        cin >>m;
        for (int i=1;i<=m;i++)
            cin >>a[i];
        for (int i=1;i<=m;i++)
        {
            if (a[i]+3*(i-1)>=60)
                break;
            if (a[i]+3*i>=60)
            {
                ans=a[i];
                break;
            }
            ans=ans-3;
        }
        cout <<ans<<endl;
    }
    return 0;
}


int main()
{
	int n , i , j , jump[ 20 ] = { 0 } , m ;

	cin >> n ;

	for( i = 1 ; i <= n ; i ++ )
	{
		memset( jump , 0 , sizeof( jump ) ) ;

		cin >> m ;

		if( m == 0 )
			cout << 60 << endl ;
		else
		{
			for( j = 0 ; j < m ; j ++ )
				cin >> jump[ j ] ;

			if( 3 * m + jump[ m - 1 ] <= 60 )
				cout << 60 - 3 * m << endl;
			else
			{
				j = 0 ;

				for( j = 0 ; 3 * ( j + 1 ) + jump[ j ] <= 60 ; j ++ ) ;

			//	cout << "j=" << j << endl ;

				if( 3 * ( j + 1 ) + jump[ j ] > 63 )
					cout << 60 - 3 * j << endl ;
				else
					cout << jump[ j ] << endl ;
			}
		}
	}
	return 0 ;
}


int main()
{
	int n, cs[999], num[99], result = 60;
	int i, j;
	scanf("%d", &n);
	for(i = 0; i < n; i++){
		scanf("%d", &cs[i]);
		for(j = 0; j < cs[i]; j++){
			scanf("%d", &num[j]);
			if(num[j] < (result - 3)){
				result -= 3;
			}
else if(num[j] >= (result - 3) && num[j] < result){
				result = num[j];
			}
		}
		cs[i] = result;
		result = 60;
	}
	for(i = 0; i < n; i++){
		printf("%d\n", cs[i]);
	}
	return 0;
}


int main()
{
	int n,i,j,k;
	struct sutdent
	{
		int faulttimes,fault[100],total,timespace[200];
	}data[100];
	for(i=0;i<100;i++)
	{
		data[i].faulttimes=0;
		for(j=0;j<100;j++)
		{
			data[i].fault[j]=0;
		}
		data[i].total=60;
		for(j=1;j<200;j++)
		{
			data[i].timespace[j]=1;
		}
	}
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&data[i].faulttimes);
		if(data[i].faulttimes==0)
		{
			continue;
		}
		else
		{
		    for(j=0;j<data[i].faulttimes;j++)
			{
			    scanf("%d",&data[i].fault[j]);
			}
		}
	}
	for(i=0;i<n;i++)
	{
		if(data[i].faulttimes==0)
		{
			continue;
		}
		else
		{
			for(j=0;j<data[i].faulttimes;j++)
			{
			    data[i].timespace[data[i].fault[j]+1+3*j]=0;
				data[i].timespace[data[i].fault[j]+2+3*j]=0;
				data[i].timespace[data[i].fault[j]+3+3*j]=0;
			}
			for(k=1;k<=60;k++)
			{
				if(data[i].timespace[k]==0)
				{
					data[i].total--;
				}
			}
		}
	}
	for(i=0;i<n;i++)
	{
		printf("%d\n",data[i].total);
	}

	return 0;
}


int main()
{
	int n,times,a[60],k,i;
	scanf("%d",&n);
	while(n>0)
	{
		n--;
		scanf("%d",&k);
		for(i=0;i<k;i++)
			scanf("%d",&a[i]);
		times=60;i=0;
		while(i<k&&a[i]<times)
		{
			if(times-3<a[i]) times=a[i];
			else times=times-3;
			i++;
		}
		printf("%d\n",times);
	}
}


int main(){
	int num;
	cin>>num;
	while(num){
	int fail;
	cin>>fail;
	if (fail==0) cout<<"60"<<endl;
	else{
	int n[fail];
	for(int i=0;i<fail;i++)
		cin>>n[i];
	int t=0;
	for(int i=0;i<fail;i++){
		t=n[i]+3*(i+1);
		if (63>t&&t>60){
			cout<<n[i]<<endl;
			break;//????3????
		}
		else if(t>=63){
			cout<<60-3*i<<endl;
			break;//??
		}
		else if (i==fail-1) cout<<60-3*(i+1)<<endl;//???????
	}
	}
	num--;
	}
	return 0;
}


int main()
{   int n,i,k,a,time,all,ans,alltime;
    scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&a);
		alltime=60; ans=0; time=0;
		for(k=1;k<=a;k++){
			scanf("%d",&all);
            if(all+k*3<=60){ time=all+k*3;
			    ans=all;
			}
			if(all+k*3==61) alltime=alltime-2;
             if(all+k*3==62) alltime=alltime-1;
		}
		ans=ans+(alltime-time);
		printf("%d\n",ans);
	}
	return 0;
}


int main()
{
	int n;
	scanf("%d",&n);
	int i;
	for(i=0;i<n;i++)
	{
		int leiji;
		scanf("%d",&leiji);

		if(leiji==0)
			printf("60\n");

		else
		{
			int j,stop[60];
			for(j=1;j<=leiji;j++)
			{
				scanf("%d",&stop[j]);
			}
			for(j=leiji;j>0;j--)
			{
				int time=stop[j]+3*j;
				int time1=stop[j]+3*j-3;
				if(time1<=60&&time>=60)
					printf("%d\n",stop[j]);
				else if(time<60)
					printf("%d\n",60-3*j);
				if(time1<=60&&time>=60)
					break;
				else if(time<60)
					break;
			}
		}

	}
	return 0;
}


int main()
{
	int n, bad, a[100]={0}, i, j, b;
	int all(int bad, int a[100]);
	scanf("%d", &n);
	for(i=0;i<n;i++){
		scanf("%d", &bad);
		if(bad==0)
			printf("60\n");
		else{
		for(j=0;j<bad;j++){
			scanf("%d", &a[j]);
		}
			b = all(bad, a);
			printf("%d\n", b);
		}
	}
	return 0;
}
int all(int bad, int a[100])
{
	int i;
	for(i=bad-1;i>=0;i--){
		if(a[i]+3*(i+1)<60)
			return (60-3*(i+1));
		else if(a[i]+3*i<=60&&a[i]+3*i>=57)
			return a[i];
		else
			continue;
	}
}


int main()
{
    int n, i, j, badall, all;
    int total[100]={60};
    scanf("%d", &n);
	j=0;
    for(i=0;i<n;i++)
    {
        scanf("%d", &badall);
		if(badall!=0)
		{
        for(j=0;j<badall;j++)
            scanf("%d", &total[j]);
        for(j=badall-1;j>=0;j--)
        {
            if(total[j]+j*3<=60)
            {
            all = 60 - (j+1)*3;
            if(all<total[j]){
            all=total[j];}
            break;
            }
        }
		}
		else all = 60;
        printf("%d\n", all);
    }
    return 0;
}


int main(int argc, char* argv[])
{
    int n, i, j, a;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		int sum=60;
		scanf("%d",&a);
		for(j=0;j<a;j++)
		{
			int b;
			scanf("%d",&b);
			if(b<(sum-3))
			{
			    sum -= 3;
			}
			else if(b>=(sum-3)&&b<=sum)
			{
				sum=b;
			}
		}
			printf("%d\n",sum);
	}
	return 0;

}


int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int c=0;
		int cmc,m,cmc1;
		int time=0;
		int q=0;
		cin>>m;
		if(m==0)
		{cout<<60<<endl;
		continue;}
		for(int j=0;j<m;j++)
		{
			if(q==1)
			{
					cin>>cmc1;
					continue;
			}
			cin>>cmc;
			if(time+cmc>=60&&q!=1)
			{
				cmc=60-time;
				q=1;
			}
			else if(time+cmc>=57&&q!=1)
			{
				q=1;
			}
			if(q==1)continue;
			time=time+3;
		}
		if(q==0)cmc=60-time;
		cout<<cmc<<endl;
	}

	return 0;
}


int main()
{
	//int ans = 60;
	int n;
	scanf("%d",&n);
	for(int i = 1;i <= n;i ++){
		//int ans = 60;
		int t;
		int temp = 0;//????
		int spe = 0;//????
		scanf("%d",&t);
		for(int i = 1;i <= t;i ++){
			int now;
			scanf("%d",&now);
			if(now + temp * 3 < 57){
				temp ++;
			}
			if(now + temp * 3 >= 57 && now + temp * 3 < 60 && spe == 0) spe = 60 - now - temp * 3;

		}
		printf("%d\n",60 - temp * 3 - spe);
	}
	return 0;
}


int main()
{
	int m,i,j,k,population;
	int sum=0;
	scanf("%d\n",&population);
	for(i=0;i<population;i++)
	{
		scanf("%d",&m);
		if(m==0)
		printf("60\n");
		else
		{	for(j=0;j<m;j++)
		{	scanf("%d",&k);
		    if(3*j+3+k<60 )
			{
				sum=57-3*j;
			}
			else if ( 3*j+k<60)
			{
				sum=k;}
		}
		printf("%d\n",sum);}
	}
}


int main()
{	int m,n,k,i,j,time,sum;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{	scanf("%d",&m);
		time=0;
	    sum=0;
	    if(m==0)
                printf("60\n");
        else
       {	 for(j=1;j<=m;j++)
        	{ 	scanf("%d",&k);
				if((k+3*j)>60&&(k-sum>=60-time))
                    continue;
            	else if(time>60)
            		continue;
            	else
            		sum=k;
            	time=k+3*j;
        	}
    	if(time<60)
            sum+=60-time;
        printf("%d\n",sum);
       }
	}
	return 0;
}


// PG 1049
int main()
{
	int n;
	scanf("%d",&n);
	int i,j,m;
	for (i=1; i<=n; i++)
	{
		scanf("%d",&m);
		int stop[20],skip;
        if (m==0) skip=60;
		for (j=0; j<m; j++)	scanf("%d",&stop[j]);
		for (j=m-1; j>=0; j--)
			if (stop[j]+3*(j+1)<=60)
			{
				skip=60-3*(j+1);
				break;
			}else if (stop[j]+3*j<=60)
			{
				skip=stop[j];
				break;
			}
		printf("%d\n",skip);
	}

	return 0;
}


int main()
{
	int n,p,i,j,temp[10];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&p);
        if(p==0) printf("60\n");
	      else
		  {
	         for(j=1;j<=p;j++)
			scanf("%d",&temp[j]);
	         for(j=p;j>0;j--)
			 {
		       if(temp[j]+3*j>63)
			   continue;

		        else if(temp[j]+3*j<=60)
				{
				printf("%d\n",60-3*j);
		       break;
				}
				else
			   { printf("%d\n",temp[j]);
			   break;
				}
			 }

		  }
		}
	return 0;
}


int main()
{
	int n;
	int rope[Number_children][Number];
	int i,j,sum,time,tmp;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		for(j=0;j<Number;j++)
			rope[i][j]=0;
	}
	for(i=0;i<n;i++)
	{
		scanf("%d",&rope[i][0]);
		for(j=1;j<1+rope[i][0];j++)
			scanf("%d",&rope[i][j]);
	}
	for(i=0;i<n;i++)
	{
		for(j=1,sum=0,time=0,tmp=1;(time<=60)&&(j<=rope[i][0]);j++)
		{
			if((rope[i][1]==0)||(rope[i][1]>=60))
			{
				printf("%d\n",60);
				tmp=0;
				break;
			}
			sum=rope[i][j];
			time=rope[i][j]+3*j;
		}
		if(tmp==0)
			continue;
		else
		{
		if(time<60)
		{
			sum=sum+60-time;
			printf("%d\n",sum);
			continue;
		}
		if(time>63)
		{
		sum=60-(j-2)*3;
		printf("%d\n",sum);
		continue;
		}
		sum=60-(j-2)*3-(3-(time-60));
		printf("%d\n",sum);
		}
	}
	return 0;
}


/**
 * ??? ???
 * ??? 1000012844
 * ??? ????
 **/

int timesPerMin( int *, int );

int main()
{
	int i, j, n;
	int failedTimes[ 100 ];
	int num[ 100 ][ 100 ] = { 0 };

	cin >> n;

	for ( i = 0; i < n; i++ )
	{
		cin >> failedTimes[ i ];
		for ( j = 0; j < failedTimes[ i ]; j++ )
		{
			cin >> num[ i ][ j ];
		}
	}

	for ( i = 0; i < n; i++ )
	{
			cout << timesPerMin( num[ i ], failedTimes[ i ] ) << endl;
	}

	return 0;
}

int timesPerMin( int num[], int failed )
{
	int i = 0;

	for ( i = 0; ;i++ )
	{
		if ( num[ i ] == 0 )
		{
			num[ i ] = 60;
			break;
		}
	}

	for ( i = 0; ;i++ )
	{
		if ( ( num[ i ] + i * 3 <= 60 ) &&
			( num[ i ] + i * 3 + 3 > 60 ) )
		{
			return num[ i ];
			break;
		}
		else
		{
			if ( num[ i ] + i * 3 + 3 <= 60 &&
				 i * 3 + 3 + num[ i + 1 ] > 60 )
			{
				return 60 - i * 3 - 3;
				break;
			}
		}
	}

}


int main()
{
int n,m,c;

scanf("%d",&n);
for(int x=1;x<=n;x++)
{
scanf("%d",&m);
int*shuzu=(int*)malloc(sizeof(int)*m);
c=0;
for(int i=0;i<m;i++)
{
scanf("%d",&shuzu[i]);
if(c+shuzu[i]<60)
if(c+shuzu[i]+3<60)
c+=3;
else
c=60-shuzu[i];
}
free(shuzu);
printf("%d\n",60-c);
}
return 0;
}


int main(){

	int n=0;
	cin>>n;
	int result[300];

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

		int s[30];
		int k=0;
		int times=0;
		int sum=60;

		do{
			cin>>s[k];
			k+=1;
		}
		while(cin.get()!='\n');

		for(int j=1;j<=s[0];j++){
			int sup=60-3*times-s[j];
			if(sup>0){
				times+=1;
				if(sup<3){
					sum-=sup;
				}
				else{
					sum-=3;
				}
			}
			else{
			break;
			}
		}

		result[i]=sum;

	}

	for(int i=0;i<n;i++){
		cout<<result[i];
		if(i<n-1){
		cout<<endl;
		}
	}

	return 0;

}


int main()
{
int n,m,k,c;

scanf("%d",&n);
while(n--)
{
scanf("%d",&m);
int*shuzu=(int*)malloc(sizeof(int)*m);
c=0;
for(int i=0;i<m;i++)
{
scanf("%d",&k);
if(c+k<60)
if(c+k+3<60)
c+=3;
else
c=60-k;
}
printf("%d\n",60-c);

}
return 0;
}


int main()
{
	struct tiao
	{
		int *ln;
		int k;
		int sumt;
	}*tiao1;
	int n;
	scanf("%d",&n);
	tiao1 = ( struct tiao *) malloc ( sizeof ( struct tiao ) * n );
	int i;
	int j;
	int f = 0;
	for ( i = 0 ; i < n ; i++ )
	{
		f = 0;
		scanf("%d",&tiao1[i].k);
		tiao1[i].ln = ( int * ) malloc ( sizeof ( int ) * tiao1[i].k );
		tiao1[i].sumt = 0;
		for ( j = 0 ; j < tiao1[i].k ; j++ )
		{
			scanf("%d",&tiao1[i].ln[j]);
		}
		if ( tiao1[i].k == 0 )
		{
			printf("60\n");
			continue;
		}
		for ( j = 0 ; j < tiao1[i].k ; j++ )
		{
			tiao1[i].sumt = ( tiao1[i].ln[j]+3*(j) );
			if ( tiao1[i].sumt >= 60 )
			{
				int tmp1;
				tmp1 =	tiao1[i].ln[j-1]+3*(j) ;
				if ( tmp1 >= 60 )
				{
					printf("%d\n",tiao1[i].ln[j-1]);
				}
				if ( tmp1 < 60 && 60 - tmp1 > 3 )
				{
					tmp1 = 60 - tmp1 + tiao1[i].ln[j-1];
					printf("%d\n",tmp1);
				}
				break;
			}
		}
		if ( tiao1[i].sumt < 57 )
		{
			tiao1[i].sumt += 3;
			j--;
			printf("%d\n",(60-tiao1[i].sumt+tiao1[i].ln[j]));
		}
		if ( tiao1[i].sumt < 60 && tiao1[i].sumt > 57 )
		{
			printf("%d\n",tiao1[i].ln[j-1]);
		}
	}
	return 0;
}


int main()
{
	int num;
	cin>>num;
	while(num--){
		int n;
		cin>>n;
		if(n==0) cout<<"60"<<endl;
		else{
			int a[20],i,sum=60,time=60;
			for(i=0;i<n;i++)
				cin>>a[i];
			for(i=0;i<n;i++){
				if(time-a[i]<=3){
					time=time-a[i];
					if(time>0) sum-=time;
					break;
				}
				else{
					time-=3;
					sum-=3;
				}
			}
			cout<<sum<<endl;
		}
	}
	return 0;
}


int main()
{
    int i,j,n,m,a,num,total=0;
    scanf("%d",&n);
    char chi[1000];
    for(i=0;i<n;i++)
    {
		scanf("%d",&m);
        for(j=1;j<=m;j++)
        {
			scanf("%d",&a);
            total=a+3*j;
            if(total>60)
            break;
        }
        gets(chi);
        if(total<=62 && total>=60)
		{
			num=total-3*j;
            printf("%d\n",num);
        }
        else if(total<60)
		{
			num=60-3*m;
            printf("%d\n",num);
        }
        else
        {
			num=60-3*(j-1);
            printf("%d\n",num);
        }
    }
}


int main()
{
  int a,a0,t,i,j,n,m;

  cin>>n;
  for(i=0;i<n;i++)
  { cin>>m;t=0;a=0;
    for(j=0;j<m;j++)
    { cin>>a;
      t+=3;//time not jumping
      a+=t;//the time that has passed so far
      if(a>60) break;
    }
	j++;
	while(j<m){cin>>a0;j++;}
    t=60-t;
    if(a>60)//it's already over when stop counting
      switch(a)
      { case 61:t++;break;
        case 62:t+=2;break;
        default:t+=3;//count one more pausing round
      }
    cout<<t<<endl;
  }
  return 0;
}


int main(){
	int n,i,k,j;
	int result;
	int zcs;
	int m,cs[100];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		result=0;
		scanf("%d",&m);
		if(m==0){
			zcs=60;
		}
		for(k=0;k<m;k++){
			scanf("%d",&cs[k]);
			for(j=m-1;j>=0;j--){
			result=cs[j]+(j+1)*3;
				if(result<=60){
				zcs=60-3*(j+1);
				break;
			}else if(result>60&&(result-3)<60){
					zcs=cs[j];
					break;
			}
			}
		}

		printf("%d\n",zcs);
	}
	return 0;
}


main()
{
      int n, total[100] = {0}, broke, time, i, j, broke_time[61] = {0}, timer;

      scanf("%d", &n);
      for(i = 0; i <= n - 1; i++)
      {
            scanf("%d", &broke);

            for(j = 1;j <= broke;j ++)
            {
                  scanf("%d", &timer);
                  broke_time[timer] = 1;
            }

            for(time = 1;time <= 60; time ++)
            {
                     total[i] ++;
                     if(broke_time[total[i]] == 1)
                     {
                                         //printf("(%d)", time);
                                         time += 3;

                                         //printf("|%d|[%d]\n", total[i], time);
                     }
                     if (time > 60) break;

            }

            for(j = 0;j <=60;j++)
            {
                  broke_time[j] = 0;
                  }

      }

      for(i = 0;i <= n-1; i ++)
      {
            printf("%d\n", total[i]);
            }
}


int N, Total, Time, PNum, Stop;
inline int Max(int x, int y)
{ return (x > y ? x : y); }
int main()
{
	cin >> N;
	for (int i = 0; i < N; i ++)
	{
		cin >> Stop;
		if (Stop == 0) {cout << "60" << endl; continue;}
		Total = 0; Time = 60;
		for (int j = 0; j < Stop; j ++)
		{
			cin >> PNum;
			if (Time - PNum - 3 * j >= 0)
			{
				Total = PNum;
				if (Time - PNum - 3 * j > 3)
				Total += Time - PNum - 3 * (j + 1);
			}
		}
		cout << Total << endl;
	}
	return 0;
}


int main()
{
	int n,m,i,j;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		int*sum=(int*)malloc(sizeof(int)*20);
		scanf("%d",&m);
		if(m==0)
		{
			printf("60\n");
			continue;
		}
		for(j=0;j<m;j++)
		{
			scanf("%d",&sum[j]);
			sum[j]+=3*(j+1);
		}
		for(j=m-1;j>=0;j--)
		{
		    if(sum[j]>=63) continue;
			else if(sum[j]<=60)
			{
				printf("%d\n",60-(j+1)*3);
				break;
			}
		    else if(sum[j]==61)
			{
				printf("%d\n",58-j*3);
				break;
			}
		    else if(sum[j]==62)
			{
				printf("%d\n",59-j*3);
				break;
			}
		}
		free(sum);
	}
	return 0;
}


void main()
{
	int m,n,i,j,k;
	int count,a[60];
	int time;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		count=0;
		scanf("%d",&m);
		for(j=0;j<m;j++)
			scanf("%d",&a[j]);
		for(k=1;k<=60;k++)
		{
			time=1;
			for(j=0;j<m;j++)
			{
				if(k==a[j])
				{
					time=4;
					break;
				}
			}
			count+=time;
			if(count>=60)
				break;
		}
		printf("%d\n",k);
	}
}


int main(int argc, char* argv[])
{
    int n,i,j,pause,t,number[60],total;
	scanf("%d",&n);
	for (j=0;j<n;j++)
	{
		scanf("%d",&pause);
		if (pause==0)
		{
			total=60;
		}
		else
		{
			for (i=1;i<=pause;i++)
			{
				scanf("%d",&number[i]);
			}
			for (i=1;i<=pause;)
			{
				t=number[i]+3*(i-1);
				if (t+3<60)
				{   total=57-3*(i-1);
					i=i+1;
				}
				if (t<60&&t+3>=60)
				{
					total=number[i];
					break;
				}
				if (t>=60)
				{
					total=63-3*i;
					break;
				}
			}
		}
		printf("%d\n",total);
	}

	return 0;
}


int main()
{
    int n;
    int a[100], num;
    int i, j;

    scanf("%d", &n);
    for (i=0; i<n; i++) {
        scanf("%d", &num);
        for (j=0; j<num; j++)
            scanf("%d", &a[j]);
        printf("%d\n", comp(a, num));
    }

    return 0;
}

int comp(int a[], int num)
{
    int i, re = 0;
    for (i=0; i<num; i++) {
        re = 3*(i+1) + a[i];
        if ((re>60) && ((re-3)<60)) /* not jump in 60 */
            return a[i];
        else if (re > 60) /* jumped in 60 */
            return 60 - 3*i;
    }
    if (re <= 60)
        return 60-3*i;
}


int main()
{
    int n, m, i, j, t, a[20];
	cin >> n;
	for(i = 1; i <= n; i++)
	{
		cin >> m;
			for(j = 0; j < m; j++)
				cin >> a[j];
			for(j = 0; j < m; j++)
			{
				t = a[j] + 3 * (j + 1);
				if(t > 60 && t < 63)
				{
					cout << a[j] << endl;
					break;
				}
				else
					if(t >= 63)
					{
						cout << 60 - 3 * j << endl;
						break;
					}
					else
						continue;
				if(t > 60)
					break;
			}
			if(j == m)
				cout << 60 - 3 * m << endl;
	}
    return 0;
}


int main()
{
	int n ;
	cin>>n ;
	for(int i = 0;i<n;i++)
	{
		int m,a[20];
		cin>>m;
		if(m==0)
			cout<<"60"<<endl;
		else if(m!=0)
		{
		for(int k = 0 ; k<m ; k++)
		{
			cin>>a[k];
		}
		for(int j=m ; j>=1 ; j--)
		{
			if((a[j-1]+3*j)>=63)
				continue ;
			else if((a[j-1]+3*j)<=60)
			{
				cout<<(60-3*j)<<endl;
				break;
			}
			else
			{
				cout<<a[j-1]<<endl;
				break;
			}
		 }
		}
	}
	return 0 ;
}


int main()
{
int num,m,i,time[21],count[21];
cin>>num;
while(cin>>m)
{
	if(m==0)                                   //????m?1
		cout<<60<<endl;
	else if(m==1)
	{
	cin>>time[1];
	if(time[1]<=57)
		cout<<57<<endl;
	else if(time[1]>60)
		cout<<60<<endl;
	else
		cout<<time[1]<<endl;
	}
	else
	{
     for(i=1;i<=m;i++)
     {
		 cin>>count[i];
		 time[i]=count[i]+3*i;
	 }
     if(time[m]<60)
	 {
	 cout<<60-3*m<<endl;

	 }
	 else
	 {
	 i=1;
	 while(i<=m)
	 {
	 if(time[i]>=60)
	 {
	 if(60-time[i-1]>count[i]-count[i-1])
		 cout<<count[i]<<endl;
	 else
		 cout<<60-time[i-1]+count[i-1]<<endl;
	 break;
	 }
	 else
		 i++;

	 }
	 }

	}
}
return 0;

}


int main()
{
	int n,i,m,j;
	int data;
	scanf("%d",&n);
	for( i = 1; i <= n; i++ )
	{
		int sum = 0;
		int flag = 1;
		int num = 0;
		scanf("%d",&m);
		for( j = 1; j <= m ; j++ )
		{
			scanf("%d",&data);
			if( data + num >= 60 && flag )
			{
				sum = 60 - num;
				flag = 0;
			}
			num += 3;
			if( data + num >= 60 && flag)
			{
				sum = data;
				flag = 0;
			}

		}
		if( sum == 0 )
			sum = 60 - num;
		printf("%d\n",sum);

	}
	return 0;
}


int main()
{
	int n;
	scanf("%d",&n);
	int i=1;
	while(i<=n){
		int sz[50];
		int m;
		int j;
		if(i!=1){
		    	printf("\n");
			}
		scanf("%d",&m);

		if(m==0){
			printf("60");
		}else{

		    for(j=0;j<m;j++){
		    	scanf("%d",&sz[j]);
			}

	    	sz[m]=60;

	    	int count=sz[0]+3;
	    	int num=sz[0];
		    for(j=1;j<=m;j++){
			    if(count+3+sz[j]-num<=60){
				    count+=3+sz[j]-num;
		     		num=sz[j];
				}else{
			    	if(count-num+sz[j]<=60){
					    num=sz[j];
				        break;
					}
			    	else{
		    			num=num+60-count;

			    		break;
					}
				}
			}

	        printf("%d",num);
		}
	    	i++;
	}
	return 0;
}


int main()
{
	int n;
    scanf("%d",&n);
	int i=0, j=0, f_num, result=0, score[20];
	for (i=0; i<n ;i++){
		scanf(" %d", &f_num);
		if (f_num==0){
			result=60;
		}
		else{
			for (j=0; j<f_num; j++){
		      scanf(" %d", &score[j]);
			  if (score[j]<= 60-3*f_num){
				  if (score[j]>= 60-3*(f_num+1)){
                      result=score[j];
				  }
				  else{
					  result= 60-3*f_num;
				  }
			  }
			  else{
				if (score[j-1]>= 60-3*(f_num- 1) && score[j-1]<= 60-3*(f_num-2)){
				result= score[j-1];
				}
				else{
				   if (score[j]<= 60-3*(f_num-1) && score[j]>=60-3*f_num){
			           result= score[j];
				   }
			       else{
					   if (score[j-1]>=60-3*(f_num-1)){
						   result= 60- 3*(f_num-2);
					   }
					   else{
						   result= 60- 3*(f_num- 1);
					   }

				   }
				}
			  }
			}
		}
        printf("%d\n", result);
	}
	return 0;
}


int main()
{
	int n;
	scanf("%d",&n);
	int i,j;
	for(i=0;i<n;i++)
	{
		int m,sum=60;
		scanf("%d",&m);
		for(j=0;j<m;j++)
		{
			int a;
			scanf("%d",&a);
			if(a<(sum-3))
			{
			    sum -= 3;
			}
			else if(a>=(sum-3)&&a<=sum)
			{
				sum=a;
			}
		}
			printf("%d\n",sum);
	}
	return 0;
}


int main()
{
    int a;int i,j,m,n,k;
    scanf("%d",&a);
    int time;int times[a];
    int jump[30][30];
    for(i=0;i<a;i++)
    {
        times[i]=60;
        scanf("%d",&m);
        for(j=0;j<m;j++)
            scanf("%d",&jump[i][j]);
        for(k=0;k<m;k++)
        {
            if(jump[i][k]>=times[i]) times[i]+=3;
            else if(times[i]-jump[i][k]==1) times[i]+=2;
            else if(times[i]-jump[i][k]==2) times[i]+=1;
            times[i]-=3;
        }
    }

    for(i=0;i<a;i++)
        printf("%d\n",times[i]);
    return 0;
}


struct jumps
{
	int error,c[100],sum,xia;
};

int main()
{
	struct jumps jump[100];
	int n,i,j;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d ",&jump[i].error);
		for(j=0;j<jump[i].error;j++)
		{
			scanf("%d ",&jump[i].c[j]);
		}
	}
	for(i=0;i<n;i++)
	{
		if(jump[i].c[jump[i].error-1]+jump[i].error*3<60)
			jump[i].xia=60-jump[i].error*3;
		else
		{
			for(j=0;j<jump[i].error;j++)
			{
				if(jump[i].c[j]>=47&&jump[i].c[j]<=49)
				{
					jump[i].xia=jump[i].c[j];
					break;
				}
				else if(jump[i].c[j]+(j+1)*3>60&&jump[i].c[j-1]+(j)*3<60)
				{
					jump[i].xia=60-(j)*3;
					break;
				}
			}
		}
	}
	for(i=0;i<n;i++)
	{
		printf("%d\n",jump[i].xia);
	}
	return 0;
}


void print(int a[],int m,int k,int n);
int main()
{
	int n,a[500],m,j,i=1,k=0;
	cin>>n;
	while(i<=n)
	{
		cin>>m;
		k++;
		if(m==0)
		{
			if(k!=n)
			{
				cout<<60<<endl;
			}
			else
			{
				cout<<60;
			}
			i++;

		continue;
		}

		for(j=1;j<=m;j++)
		{
			cin>>a[j];
		}
	    print(a,m,k,n);
		i++;
	}
  return 0;
}
void print(int a[],int m,int k,int n)
{

	    if(a[m]+3*m<60)
		{
			if(k!=n)
			{
				cout<<(60-3*m)<<endl;
			}
			else
			{
				cout<<(60-3*m);
			}
		}
		else if(a[m]+3*m>=60&&a[m]+3*m<=62)
		{
			if(k!=n)
			{
				cout<<a[m]<<endl;
			}
			else
			{
				cout<<a[m];
			}
		}

		else
		{
		   print( a, m-1,k,n);
		}
}


int main()
{
int n;
cin>>n;
while(n-->0)
{
	int stop,num[60],beat=60;
	cin>>stop;
	for(int i=0;i<stop;i++)
	{
		cin>>num[i];
	}
	for(int i=0;i<stop;i++)
		if(num[i]+3*(i+1)<=60)
					beat=60-3*(i+1);
				else if(num[i]+3*i>=60) {
					beat=beat=60-3*(i);
					break;
				}
				else {
					beat=num[i];
					break;
				}
	cout<<beat<<endl;
}
return 0;
}


int main(){
    int n,m,a,b,zongshu[1000];
    scanf("%d",&n);
    for(a=0;a<n;a++){
        scanf("%d",&m);
        if(m==0){
            printf("60\n");
            continue;
        }
        for(b=1;b<=m;b++){
            scanf("%d",&zongshu[b]);
        }
        for(int k=m;k>=0;k--){
            if((zongshu[k]+3*k)<=60){
                printf("%d\n",60-3*k);
                break;
            }
            else if((zongshu[k]+3*k-3)<=60){
                printf("%d\n",zongshu[k]);
                break;
            }
            else continue;
        }
    }
    return 0;

          }


int main()
{
	int counts[16] = {0}, n, m, i, j, flag, time;
	cin >> n;
	for (i = 1; i <= n; i++)
	{
		flag = time = 0;
		cin >> m;
		if (m == 0)
		{
			cout << 60 << endl;
			time = 60;
		}
		for (j = 1; j <= m; j++)
		{
			cin >> counts[j];
		}
		for (j = 1; j <= m; j++)
		{
			flag += counts[j] - counts[j - 1];
			time += counts[j] - counts[j - 1];
			if (time >= 60)
			{
				cout << flag - time + 60 << endl;
				break;
			}
			time += 3;
			if (time >= 60)
			{
				cout << flag << endl;
				break;
			}
		}
		if (time < 60)
		{
			cout << flag - time + 60 << endl;
		}
	}
	return 0;
}


int main()
{
    int people;
    cin>>people;
    int num=0;
    while(true)
    {
        int badjump[20]={0};
        int n;
        cin>>n;
        for(int i=0;i<=n-1;i++)
        {
            cin>>badjump[i];
        }
        int realtime;
        int realjump=0;
        int j=0;
        for(realtime=1;;realtime++)
        {
            realjump++;
            if(realtime==3*j+badjump[j])
            {
                realtime+=3;
                j++;
            }
            if(realtime>=60)break;

        }
        cout<<realjump<<endl;

        num++;
        if(num==people)break;
    }
    return 0;
}


int main()
{
	int n, m, i , j, current, lost;
	cin >> n;
	for( i = 0; i < n; i++)
	{
		cin >> m;
		lost = 0;
		for (j = 0; j < m; ++j)
		{

			cin >> current;
			if ((lost + current) < 60 )
			{
				if( 60 - current - lost > 3)
				lost += 3;
			    else
				lost = 60 - current ;
			}
		}
		cout << 60 - lost << endl;
	}
	return 0;
}


int main()
{
    int i,j,n,m,a,total=0,b;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
                    scanf("%d",&m);
					if(m==0)
					{printf("60\n");
					}
					else
					{
                    for(j=1;j<=m;j++)
                    {scanf("%d",&a);
					if(total<60)
                    {total=a+3*j;
                    b=j;
					}
                    }
                    if(total<=62&&total>=60)
                    {total-=3*b;

                    }
                    else if(total<60)
                    {total=60-3*m;

                    }
                    else
                    {total=60-3*(b-1);

                    }
                    printf("%d\n",total);
					}
    }

	return 0;
}


int main()
{
int n, interuptCount, currentNum, sec, lostTime ;
const int maxSeconds = 60;
cin >> n;
for (int i = 0; i < n; ++i)
{ cin >> interuptCount;
lostTime = 0;
for (int j = 0; j < interuptCount; ++j)
{ cin >> currentNum;
sec = currentNum + lostTime;
if (sec < maxSeconds)
if ((maxSeconds - sec) > 3)
lostTime += 3;
else
lostTime += maxSeconds - sec;
}
cout << maxSeconds - lostTime << endl;
}
	return 0;
}


int minute(int x,int y,int z,int xx,int yy,int zz )
{
    int result=0;
    result+=(60-y-1)*60+60-z;
    result+=(xx-x-1+12)*3600;
    result+=yy*60+zz;
    return result;
}
int main()
{
    int t=0,result=0;;
    int a,b,c,d,e,f;
    while(1)
    {
        scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
        if(a==0&&b==0&&c==0&d==0&&e==0&f==0)
            break;
        t++;
        if(t!=1)
            printf("\n");
        printf("%d",minute(a,b,c,d,e,f));
    }
	return 0;
}


main()
{
      int a,b,c,d,e,f,sum,second;
      int h,m,s;
      sum=1;

      while  (sum!=0)
      {
             scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
             sum=a+b+c+d+e+f;

             if  (f<c)
             {
                 e=e-1;
                 s=f+60-c;
             }
             else
             s=f-c;

             if  (e<b)
             {
                 d=d-1;
                 m=e+60-b;
             }
             else
             m=e-b;

             h=d+12-a;

             second=h*3600+m*60+s;

             if  (sum!=0)
             printf("%d\n",second);
      }

}


void qkg(char *a);
void qdykg(char *a);
void dbx(char *a);
int main(){
	int a,b,c,d,e,f;
	int sw;
	int xw;
	while(1){

		scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
		if(a==0){
			break;
		}
		sw=(12-a)*3600-b*60-c;
		xw=d*3600+e*60+f;
		int ans=sw+xw;
		printf("%d\n",ans);
	}
	return 0;
}
void qkg(char *a){
	int len;
	len=strlen(a);
	int i,j=0;
	char b[100];
	for(i=0;i<len;i++){
		if(a[i]!=' '){
			b[j]=a[i];
			j++;
		}
	}
	b[j]='\0';
	strcpy(a,b);
}
void qdykg(char *a){
	int len;
	len=strlen(a);
	int i,j=0;
	char b[101];
	for(i=0;i<len;i++){
		if(a[i]!=' '){
			b[j]=a[i];
			j++;
		}else if(a[i]==' '&&a[i+1]!=' '){
			b[j]=a[i];
			j++;
		}
	}
	b[j]='\0';
	strcpy(a,b);
}
void dbx(char *a){
	int len;
	len=strlen(a);
	int i;
	for(i=0;i<len;i++){
		if(a[i]>='A'&&a[i]<='Z'){
			a[i]+='a'-'A';
		}
	}
}


int minute(int x,int y,int z,int xx,int yy,int zz )
{
    int result=0;
    result+=(60-y-1)*60+60-z;
    result+=(xx-x-1+12)*3600;
    result+=yy*60+zz;
    return result;
}
int main()
{
    int t=0;
    int a,b,c,d,e,f;
    while(1)
    {

        scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
        if(a==0&&b==0&&c==0&d==0&&e==0&f==0)
        {
            break;
        }
        t++;
        if(t!=1)
        {
            printf("\n");
        }
        printf("%d",minute(a,b,c,d,e,f));

    }

	return 0;
}


int miaoshu(int a,int b,int c,int d,int e,int f);
int main()
{
	int a,b,c,d,e,f;
	int i,ms;
	for(i=0;;i++){
		scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
		ms=miaoshu(a,b,c,d,e,f);
		if(a==0&&b==0&&c==0&&d==0&&e==0&&f==0) break;
		printf("%d\n",ms);
	}
	scanf("%d",&ms);
	return 0;
}
int miaoshu(int a,int b,int c,int d,int e,int f){
	int ms1,ms2,ms;
	ms1=a*60*60+b*60+c;
	ms2=d*60*60+e*60+f;
	ms=43200-ms1+ms2;
	return ms;
}


int main(){
	int a,b,c,d,e,f;
	int sum=0,tmp;
	int r;
	int m,n,p;
	do{
	    scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
		if(a!=0)
		{
		 m=(d+12-a)*3600;
		  n=(e-b)*60;
		  p=f-c;
		tmp=m+n+p;
		printf("%d\n",tmp);
		}
		if(a==0)
		{
			continue;
		}
	}while(a!=0);
	return 0;
}


int main(){
	int a,b,c,d,e,f;
	int hour,min1,min2,sec1,sec2,result;

	while(scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f)){
	if(a!=0||b!=0||c!=0||d!=0||e!=0||f!=0){
		min1=59-b;
		sec1=60-c;
		min2=e;
		sec2=f;
		hour=12+d-(a+1);

		result=hour*60*60+min1*60+min2*60+sec1+sec2;
		printf("%d\n",result);
	}
	else
		break;
	}
	return 0;

}


int i(int a,int b,int c)
{
	return(a*3600+b*60+c);
}
main()
{
	int a,b,c,d,e,f;
	int sum;
	for(;;)
	{
		scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
		if(a==0) break;
		else
		{
			sum=i(d,e,f)+3600*12-i(a,b,c);
			printf("%d\n",sum);
		}
	}
	return 0;
}


int main()
{
	int a,b,c,d,e,f;
	double begin,end;
	scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
	while(a!=0){
		begin=3600*a+60*b+c;
		end=3600*(d+12)+60*e+f;
		printf("%.0lf\n",end-begin);
		scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
	}
	return 0;
}


// ?????.cpp : Defines the entry point for the console application.
//

int main(int argc, char* argv[])
{
	int a,b,c,d,e,f;
	scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
	while(a!=0||b!=0||c!=0||d!=0||e!=0||f!=0){
		d+=12;
		printf("%d\n",(d-a)*3600+(e-b)*60+(f-c));
		scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
	}
	return 0;
}


int main()
{
  int a,b,c,d,e,f;
  int i,time=0;
  for(i=0;i<10000;i++){
     scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
     time=time+(d+12-a)*60*60;
	 time=time+(e-b)*60;
	 time=time+f-c;

	 if(time==12*60*60){
	 break;
	 }
	 if(time!=0){
	 printf("%d\n",time);
	 time=0;
	 }
  }
    return 0;
}


int main(){
	int a,b,c,d,e,f;
	int result;
	int m,n;
	for(int i=1;;i++){
     	scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
		if(a==0){
			break;
		}
		else {
    	d=d+12;
	    result=3600*(d-a)+(e-b)*60+(f-c);

		  printf("%d\n",result);
		}

	}
	return 0;
 }


int g(int ,int ,int ,int ,int ,int );
int main()
{
	int a,b,c,d,e,f,i,s;
	a=b=c=d=e=f=1;
	while(1)
	{
		scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
		if((a*a+b*b+c*c+d*d+e*e+f*f)!=0)
		{
			s=g(a,b,c,d,e,f);
		    printf("%d\n",s);
		}
		else
			break;
	}
	return 0;
}
int g(int a,int b,int c,int d,int e,int f)
{
	int x=0,y,z;
	y=a*3600+b*60+c;
	z=(d+12)*3600+e*60+f;
	x=z-y;
	return x;
}


int main()
{
	int a,b,c,d,e,f;
	int n;
	int result;
	for(n;n;n++){
		scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
		if(a==0&&d==0){
			break;
		}else{
			d=d+12;
			result=3600*(d-a)+60*(e-b)+(f-c);
			printf("%d\n",result);
		}
	}
	return 0;
}


int main()
{
	int a,b,c,d,e,f,i;
	int miaoshu1,miaoshu2,jieguo;
	for(i=1;i<=10086;i++){
		scanf("%d %d %d %d %d %d\n",&a,&b,&c,&d,&e,&f);
		if(a<1||d>11||b<0||f>59){
			break;
		}else{
			miaoshu1=a*3600+b*60+c;
			miaoshu2=(d+12)*3600+e*60+f;
			jieguo=miaoshu2-miaoshu1;
			printf("%d\n",jieguo);
		}
	}
	scanf("0 0 0 0 0 0");
	return 0;
}


int time(int a,int b,int c);
int main(){
	int a,b,c,d,e,f,mor,aft,second;
	while(1){
		scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
		if(a==0&&b==0&&c==0&&d==0&&e==0&&f==0){
			break;
		}
		d+=12;
		mor=time(a,b,c);
		aft=time(d,e,f);
		second=aft-mor;
		printf("%d\n",second);
	}
	return 0;
}
int time(int a,int b,int c){
	int second;
	second=0;
	second+=3600*a;
	second+=60*b;
	second+=c;
	return second;
}


int main()
{
	int a,b,c,d,e,f;
	int result;
	do
	{
		scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
		if (a!=0)
		{
			result=(N*N-b*N-c)+(d-a+11)*N*N+(e*N+f);
			printf("%d\n",result);
		}
	}
	while(a!=0);
	return 0;
}


int main()
{
	int i,m=0;
	char *p=NULL;
	char c[31];
	gets(c);
	p=c;
	for ( i=0;i<strlen(c);i++)
		{
			if ( *p >= '0' && *p <= '9')
				{
					cout << *p;
					m=1;
				}
			else if ( m == 1 )
				{
					cout << endl;
					*p;
					m=0;
				}
			*p++;
		}
	cout << endl;

	return 0;
}


int main()
{
    char input[31];
    int i;

    for(i = 0; i < 31; i ++)
        input[i] = '\0';

    gets(input);

    for(i = 0; i < 30; i ++)
        if(input[i] >= '0' && input[i] <= '9')
        {

            printf("%c", input[i]);

        }
        else
        {
            printf("\n");
        }

        return 0;
}


int main ()
{
	char str[50] ;
	int i ;
	cin.getline(str , 50) ;
	for (i = 0 ; str[i] != '\0' ; i ++)
	{
		if (str[i] >= 48&&str[i] <= 57)
		{
			cout << str[i] ;
		}
		else
		{
			if (str[i - 1] >= 48&&str[i - 1] <= 57)
			{
				cout << endl ;
			}
		}
	}
	cout << endl ;
	return 0 ;
}


main()
{
    char str[31];
    gets(str);
    int n;
    n=strlen(str);
    for(int i=0;i<n;i++)
    {
        if(str[i]>='0'&&str[i]<='9')
            printf("%c",str[i]);
        else
        {
            printf("\n");
            for(;str[i]<'0'||str[i]>'9';i++)
            {}
            i--;
        }
    }
    getchar();
}


int main()
{
char str[1000];
while(cin>>str)
{for(int i=0;i<strlen(str);i++)
{
if((str[i]>='0')&&(str[i]<='9')) cout<<str[i];
else cout<<endl;
}
}
return 0;
}


int main()
{
	char word[31];
	int i=0,flag=0,flags=0,j=0;
	int len=0;
	cin.getline(word,31,'\n');
	len=strlen(word);
	for(i=0;i<len+1;i++)
	{
		if(word[0]<'9'&&word[0]>'0')
		{
			if(word[i]>'9'||word[i]<'0')
			{
				if(flag==0)
				{
					for(j=flag;j<flags;j++)
					{
						cout<<word[j];
					}
				}
				else
				{
					for(j=flag+1;j<flags;j++)
					{
						cout<<word[j];
					}
				}
				if(flags-flag>1&&flag>0)
					cout<<endl;
				else if(flags-flag>=1&&flag==0)
					cout<<endl;
				flag=flags;
				flags++;
			}
			else
			{
				flags++;
			}
		}
		else
		{
			if(word[i]>'9'||word[i]<'0')
			{
				for(j=flag+1;j<flags;j++)
				{
					cout<<word[j];
				}

				if(flags-flag>1)
					cout<<endl;
				flag=flags;
				flags++;
			}
			else
			{
				flags++;
			}
		}
	}
	return 0;
}


int main() {
	char str[31];
	int i,j;
	gets(str);
	for(i=0;str[i]!=0;i++){
		if(str[i]>=48&&str[i]<=57){
			for(j=i;str[j]>=48&&str[j]<=57;j++)
				cout<<str[j];
			cout<<endl;
			i=j;
		}
	}

	return 0;
}


int main()
{
	char a[30];
	gets(a);
	int m=0;
	for(int i=0;i<30;i++)
	{
		if(a[i]>=48&&a[i]<58)
		{
			cout <<a[i];
			m=1;
		}
		else if(m==1)
		{
			cout <<endl;
			m=0;
		}
		else
			continue;
	}
	if(m==1)
		cout <<endl;
	return 0;
}


int main()
{
	int n,i,j,k;
	char a[30];
	char *s;
	gets(a);
    s=a;
	n=strlen(a);
      for(i=0;i<n;i++)
	  {if(*(s+i)>='0'&&*(s+i)<='9')
		  {
			  j=0;
			  printf("%c",*(s+i));
		  }
		  else
			  if(j==0)
			  {  printf("\n");
	  continue;}
			  else
				  continue;
}
 return 0;
}


char x[1000];
int main()
{
    int i,len;
    gets(x+1);
    x[0]='0';
    len=strlen(x+1);
    for(i=1;i<=len;i++)
    {
                      if(isn(x[i])&&!isn(x[i-1]))
                      printf("\n");
                      if(isn(x[i]))
                      printf("%c",x[i]);
    }
   //a getch();
    return 0;
}


/*           ????
??????      2010.12.12        */
int main()
{
	int num,flag=0;
	char a[50];
	char *p;
	cin.getline(a,sizeof(a));
	a[strlen(a)]='a';
	for(p=a;p<a+strlen(a);p++)
		if(*p<='9'&&*p>='0')
		{
			if(flag)
				num=num*10+*p-'0';
			else
				num=*p-'0';
			flag=1;
		}
		else
		{
			if(flag==1)
				cout<<num<<endl;
			flag=0;
		}
	return 0;
}


/**
* @file 1000012907_3.cpp
* @author ???
* @date 2010?12?11
* @description
* ??????: ????
*/
int main()
{
	char str[31];
	int len, i, flag;
	char *p = str;
	gets(str);
	len = strlen(str);
	for (p = str; p < str + len; p++)
	{
		if (*p - '0' >= 0 && *p - '0' <= 9)
		{
			cout << *p;
			flag = 0;
		}
		else if (flag == 0)
		{
			cout << endl;
			flag = 1;
		}
	}
	return 0;
}


int detc(char m)
{
	if(m>=48&&m<=57)return 1;
	else return 0;
}
int main()
{
	char c[30];
	int i,j,k;
	int m,n;
	cin.getline(c,31,'\n');
    n=strlen(c);
	for(i=0;i<=n-1;i++)
	{
		if((i==0&&detc(c[i])==1)||i!=0&&detc(c[i])&&!detc(c[i-1]))
		{
			for(j=0;detc(c[i+j])==1;j++)
			{cout<<c[i+j];}
			cout<<endl<<endl;
		}
	}
	return 0;
}


/** c version **/

int isDigit(char ch) {
    if (ch == '\0') return -1;
    if ('0' <= ch && ch <= '9') return 1;
    return 0;
}

int main() {
    char *p = (char *) malloc(40 * sizeof(char));
    gets(p);
    do {
        p--;
        while (isDigit(*(++p)) == 0) {} // ignore non-digit chars
        p--;
        while (isDigit(*(++p)) == 1)
            printf("%c", *p);
        printf("\n");
    } while (*p != '\0');
    return 0;
}


int main(){
  int tmp=-1;
  char ch;
  while (scanf("%c",&ch)!=EOF){
    if ((ch<48)||(ch>57)){
      if (tmp>=0)
        printf("%d\n",tmp);
      tmp=-1;
    }else{
       if (tmp<0)
         tmp=ch-48;
       else
         tmp=tmp*10+ch-48;
    }
  }
  if (tmp>=0)
    printf("%d\n",tmp);
}


char a[33];
int main()
{
char *p;
p=&a[0];
int flag=0;
cin.getline(a,32);
while(1)
{
if(*p<='9'&&*p>='0')
{
flag=0;
cout<<*p;
p++;
}
else if(flag==0)
{
cout<<endl;
flag=1;
p++;
}
else p++;
}
}


int main(){
	int l,i,t=0;
	char a[40];
	cin.getline(a,31);
	l=strlen(a);
	while(1){
	for(i=t;i<l;i++){
	if(a[i]>='0'&&a[i]<='9')
	cout<<a[i];
	else break;
	}
	if(i>l-1) break;
	cout<<endl;
	while(i<l){
		if(a[i]<='9'&&a[i]>='0')
			break;

			i++;
	}
	t=i;

	if(i>l-1) break;
	}
}


int main(void)
{
    char fib[SIZE];
    int i=1;
    int t=1;
    int loser[SIZE];
    char *ptr;
    loser[0]=-1;

    gets(fib);

    for(i=0;i<strlen(fib);)
                          {
                         if((fib[i]>='0')&&(fib[i]<='9'))
                         i++;

                         else
                          loser[t++]=i++;
                         }
    loser[t]=strlen(fib);
    ptr=&fib[0];
    for(i=0;i<t;i++)
     {
                         for(;loser[i]<loser[i+1]-1;loser[i]++)
                         {
                         printf("%c",*(ptr+loser[i]+1));
                         }
      if((*(ptr+loser[i])>='0')&&(*(ptr+loser[i])<='9'))
      printf("\n");

      }

    return 0;
}


int main()
{
    int n, i;
    char num[30];
    gets(num);

    n=strlen(num);
    for(i=0;i<n;i++)
    {
        if(num[i]!=96&&num[i]!=109)
        {
            while(num[i]>=48&&num[i]<=57)
            {
                putchar(num[i]);
                i++;
                continue;
            }
        }
        printf("\n");
    }

    return 0;
}


/*
 * tiqushuzi.cpp
 *
 *  Created on: 2012-12-13
 *      Author: alias
 */
int main(){
	char str[31];
	cin.getline(str,sizeof(str));
	int len = strlen(str);
	for (int i = 0;i < len;i++){
		if (*(str+i) >= '0'&&*(str+i) <= '9')
			cout << *(str+i);
		else{
			if (*(str+i+1) >= '0'&&*(str+i+1) <= '9')
				cout << endl;
			}
	}
	return 0;
}


/*
 * tiqushuzi.cpp
 *
 *  Created on: 2012-12-13
 *      Author: Lenovo
 */
int main()
{
	char array[33];
	char *point = NULL;
	int sum=0;
	cin.getline(array,33);
	point = array;
	for(;point<strlen(array)+array;point++)
	{
		if((*point<48||*point>57)&&sum==0)
		{
			cout<<endl;
			sum++;
		}
		else if((*point<48||*point>57)&&sum>0)
		{}
		else
		{
			cout<<*point;
			sum=0;
		}
	}
	return 0;
}


char str[31];
void number(int position)
{
    int i;
    if (!*(str+position)) return;
    else if(*(str+position)<='9'&&*(str+position)>='0'&&*(str+position-1)!='-')
    {
        for (i=position;*(str+i)<='9'&&*(str+i)>='0';i++)
            cout<<*(str+i);
        cout<<endl;
        number(i);
    }
    else if (*(str+position)<='9'&&*(str+position)>='0'&&*(str+position-1)=='-')
    {
        for (i=position;*(str+i)<='9'&&*(str+i)>='0';i++);
        number(i);
    }
    else   number(position+1);
}
int main()
{
    int i;
    gets(str);
    number(0);
}


int main()
{
	char c[32];
	gets(c);
	int state = 0;
	for(int i = 0;i < strlen(c);i++)
	{
		if( * (c + i) >= '0' && *(c + i) <= '9')
		{
			if(state == 1)
			{
				cout<<endl;
				state = 0;
			}
			cout<<*(c+i);
		}
		else
		{
			if(state == 0)
			{
				state = 1;
			}
		}
	}
}


int main(){
	char m[31];
	char *pointer;
	int i,len,flag=0;
	cin.getline(m,31);
	len=strlen(m);
	pointer=&m[0];
	for(i=0;i<len;i++){
		pointer=&m[i];
		if(*pointer>=48&&*pointer<=57){
			cout<<*pointer;
			flag=1;
		}
		else{
			if(flag==1)
				cout<<endl;
			flag=0;
		}
	}
	return 0;
}


int function(int n)
{

}
int main()
{
    char str[30];
    cin.getline(str,40,'\n');
    int i=0,n=strlen(str);
    for(i=0; i<n; i++)
    {
        if(str[i]>='0'&&str[i]<='9'&&str[i-1]!='-')
            cout<<str[i];
        else if(i==0||(str[i-1]<'0'||str[i-1]>'9'))
            continue;
        else
            cout<<endl;
    }
   return 0;
}


int p(int a)
{
    int sum=1;
    for(int i=0;i<a;i++)
    {
            sum=sum*10;
    }
    return sum;
}
int main()
{
    char str[31];
    cin.getline(str,31);
    int len=strlen(str),num[30],j=0,k=0;
    memset(num,0,sizeof(num));
    for(int i=len-1;i>=0;i--)
    {
            if((str[i]<='9')&&(str[i]>='0'))
            {
                   num[k]=num[k]+(str[i]-'0')*p(j);
                   j++;
            }
            else if((str[i+1]<='9')&&(str[i+1]>='0'))
                 {
                                                     j=0;
                                                     k++;
                 }
                 else continue;
    }
    if((str[0]>'9')||(str[0]<'0'))  k--;
    for(int i=k;i>=0;i--)  cout<<num[i]<<endl;
    return 0;
}


void main()
{
	char *str;int *a;
	str=(char*)malloc(30*sizeof(char));
	a=(int*)malloc(30*sizeof(int));

	gets(str);
	int i;
	for(i=0;i<strlen(str);i++)
	{
		*(a+i)=*(str+i);

	}
			for(i=0;i<strlen(str);i++)
	       if(*(a+i)>=48&&*(a+i)<=57)
		{

		printf("%c",*(str+i));

		if(1-(*(a+i+1)<=57&&*(a+i+1)>=48))
			printf("\n");
		}

}


int main()
{ void prt(char a[],int n);
	int n=0;
  char a[31]={'\0'};
  gets(a);
  n=strlen(a);
  prt(a,n);
  getchar();
  getchar();
  return(0);
}
void prt(char a[],int n)
{ int i=0,t=0;
  for(i=0;i<n;i++)
  {  switch (a[i])
   { case '1':
    case '2':
    case '3':
	case '4':
	case '5':
	case '6':
	case '7':
	case '8':
	case '9':
	case '0':printf("%c",a[i]);t=0;break;
  default:
	  if(i<n-1)
	  {if(t==0) {t=1;printf("\n");}}
	  break;
   }

  }

}


int main()
{
  char str[50];
  cin.getline(str,40,'\n');
  int i,len;
  len=strlen(str);
  for(i=0;i<=len-1;i++)
  {
    if(str[i]>='0'  &&  str[i]<='9')
	{
		cout<<str[i];
	    if(i!=len-1)
		{
			if(str[i+1]<'0'  ||  str[i+1]>'9')
			cout<<endl;
		}
	}
  }

return 0;
}


/**
* @author ??
* @date 2010-12-8
* @description
* ??????:????
*/

int main()
{
	int flag = 1, count = 0;
	char str[31];
	cin.getline(str, 31);
	char *a = str;
	for (int i = 0; *(a + i) != '\0'; i++)
	{
		if (*(a + i) >= 48 && *(a + i) <= 57)
		{
			if (!flag)
				flag = 1;
			if (flag == 1)
				count ++;
			flag = 2;
			cout << *(a + i);
		}
		else
		{
			if (flag)
				cout << endl;
			flag = 0;
		}
	}
	cout <<endl;

	return 0;
}


char* getmemory(int num)
{
	char *p=(char*)malloc(num*sizeof(char));
	return p;
}

void main()
{
	char *str,*p1,*a;
	int n,m,k;
	str=getmemory(31);
	gets(str);
	n=strlen(str);
	p1=a=str;
	k=0;
	for(;*str!='\0';)
	{
		if(*str<'0'||*str>'9')
		{
			k+=1;
			if(*(str+1)>='0'&&*(str+1)<='9')
			{
				m=str-k-p1;
				if(p1==a){for(;p1<=str-k;p1++)printf("%c",*p1);printf("\n");}
				else {for(p1=p1+1;p1<=str-k;p1++)printf("%c",*p1);printf("\n");}
				p1=str;
				k=0;
			}
		}
		str++;
	}
	if(p1==a)
		for(;p1<str-k;p1++)printf("%c",*p1);
	else
		for(p1=p1+1;p1<str-k;p1++)printf("%c",*p1);

}


int main()
{
	char *org;
	org=(char*)malloc(30*sizeof(char));
	gets(org);
	int i,j,count;
	for(i=0;*(org+i)!='\0';i++)
	{
		if(*(org+i)>='0'&&*(org+i)<='9')
		{
			count=0;
			printf("%c",*(org+i));
		}
		else
		{
			if(i!=0&&count==0)printf("\n");
			count++;
		}
	}
}


/*
 * 04.cpp
 *
 *  Created on: 2014-1-4
 *      Author: Administrator
 */
int main()
{
	int i,k=0,s;
	char a[100];
	gets(a);
	s=strlen(a);
	for(i=0;i<s;i++)
	{
		if(a[i]-'0'>=0&&'9'-a[i]>=0)
		{
			cout<<a[i];
			k=1;
		}
		else
			if(k==1)
			{
				cout<<endl;
				k=0;
			}
	}
	return 0;
}


int main()
{
	char c;
	int flag = 0;
	c = cin.get();
	while (c != '\n')
	{
		if (c >= '0' && c <= '9')
		{
			if (flag == 0 && c == '0')
			{
				while (c != '0')
					c = cin.get();
			}
			cout << c;
			flag = 1;
		}
		else if (flag)
		{
			cout << endl;
			flag = 0;
		}
		c = cin.get();
	}
	return 0;
}


void main()
{ char*str,*p;int k=1;
  str=(char *)malloc(40*sizeof(char));
  gets(str);
  p=str;
  for (;*p!='\0';p++)
  { if (*p>='0'&&*p<='9')
    {printf("%c",*p);k=1;}
    else if(k=1) {printf("\n");k=0;}
  }
}


int main()
{
	char str[35];
	int i;
	gets(str);
	for(i=0;i<strlen(str);i++)
	{
		if(str[i]>='0'&&str[i]<='9')
		{
			cout<<str[i];
		}
		else
		{
			if(str[i+1]>='0'&&str[i+1]<='9')
			{
				cout<<endl;
			}
		}
	}
	if(str[strlen(str)-1]>='0'&&str[strlen(str)-1]<='9')
	{
		cout<<endl;
	}
	else
	{
		;
	}
	return 0;
}


int main(){
    int c,state = 0;
    while((c = getchar())!=EOF){
    switch(state){
    case 0:
        if(isdigit(c)){
            putchar(c);
            state = 1;
        }
        break;
    case 1:
        if(!isdigit(c)){
            putchar('\n');
            state = 0;
        }
        else putchar(c);
        break;
    }
    }
    return 0;
}


int main()
{
   char s[40];
   gets(s);
   int i;
   for(i=0;i<strlen(s);i++)
   {
	   if(isdigit(*(s+i))!=0)
	   {
		   cout<<*(s+i);
	   }
	   else
	   {
		   if(isdigit(*(s+i-1))!=0)
		   cout<<endl;
	   }

   }

   return 0;
}


int main(){
	int i,number=0;
	char string[31];
	cin.getline(string,50);
	for(i=0;string[i]!=0;i++){
		if(string[i]>='0'&&string[i]<='9')cout<<string[i];
		else if(i!=0)
			if(string[i-1]>='0'&&string[i-1]<='9'){
				cout<<endl;
				number++;
			}
	}
	number++;
	cout<<endl;
	return 0;
}


/*
 * extractnum.cpp
 *
 *  Created on: 2011/12/25
 *      Author: guyu
 */
char b[31];
float remembernum[31];
char num[31][31];
void modify(char a[],int len)//delete all the blanks
	{
		int i=0,j=0;
		for(i=0;i<len;i++)
			if(a[i]==' ')
			{
				for(j=i;j<len;j++)
					a[j]=a[j+1];
			}
	}
void converse(char a[],int len)
	{
		int i=0,j=0;
		for(i=0;i<len;i++)
		{
			if(a[i]>='0'&&a[i]<='9')
			{
				for(j=i;j<len;j++)
				{
					if(a[j]<'0'||a[j]>'9')
						{cout<<endl;break;}
					else
					{
						cout<<a[j];
					}
				}
				i=j;
			}
		}
	}
int main()
{
	char a[31];
	cin.getline(a,31);
	int len,len1;
	len=strlen(a);
	modify(a,len);
	len1=strlen(a);
	converse(a,len1);
	return 0;
}


int main() {
    int a;
    while (!cin.eof()) {
        while (!cin.eof() && !isdigit(cin.peek())) // not digit
            cin.get(); // ignore
        if (cin >> a) // digit, not eof
            cout << a << endl;
    }
    return 0;
}


int main()
{
	char c[30],*a;
	int i,d;
	gets(c);
	d=strlen(c);
	for(a=c+0;a<=c+d-1;a++)
		{
			if(isdigit(*a))
			printf("%c",*a);
			else if(!isdigit(*a)&&a>(c+0)&&isdigit(*(a-1)))
				printf("\n");
	}
	return 0;
}


int judge(char x){
	if(x>47&&x<58){return 1;}
	return 0;}
int main (){
	int i,all,count,start[30],end[30],p;
	char sen[31];
	gets(sen);
	all=strlen(sen);
	count=0;
	for(i=0;i<all-1;i++){
		if(i==0){if(judge(sen[i])){start[0]=0;count++;}}
		if(i!=0&&(!(judge(sen[i-1])))&&judge(sen[i])){start[count]=i;count++;}
		if(judge(sen[i])&&(!judge(sen[i+1]))){end[count-1]=i;}}
	if(judge(sen[all-2])&&judge(sen[all-1])){end[count-1]++;}
	if((!judge(sen[all-2])&&judge(sen[all-1]))){start[count]=all-1;end[count]=all-1;count++;}
	if(end[count-1]<0||end[count-1]>30){end[count-1]=all-1;}
	for(i=0;i<count;i++){

		for(p=start[i];p<=end[i];p++){printf("%c",sen[p]);}

		printf("\n");}

return 0;}


void main()
{
	int l;
	char *a,*p;
	a=(char*)malloc(30*sizeof(int));
	gets(a);

	l=strlen(a);
	for(p=a;p<a+l;p++)
	{
		if((*p>=48)&&(*p<=57))
		{
			printf("%c",*p);
		}
		else
		{
			printf("\n");
		}
	}
	printf("\n");
}


/*
 * tiqushuzi.cpp
 *
 *  Created on: 2012-12-14
 *      Author: asus
 */

int main()
{
    char s[40];
    cin.getline(s,40);
    int t = 0;
    char temp[40];
    for(int i = 0; i < strlen(s); i++)
    {
        if(s[i] >= '0'&&s[i] <= '9')
        {
            t++;
            temp[t] = s[i];
            if(i == strlen(s) - 1)
            for(int i = 1; i <= t; i++)
            cout << temp[i];
            continue;
        }
        else if(t != 0)
        {
            for(int i = 1; i <= t; i++)
            cout << temp[i];
            cout << endl;
            t = 0;
        }
    }

}


int main()
{
	char string[35];
	cin.getline(string,35);
	int i,lenth=strlen(string);
	for(i=0;i<lenth;i++)
	{
		if(string[i]>='0'&&string[i]<='9')
			if(string[i-1]!='-')
				for(;i<lenth;i++)
				{
					if(!(string[i]>='0'&&string[i]<='9'))
					{
						cout<<endl;
						break;
					}
					cout<<string[i];
				}
	}
	return 0;
}


void main()
{
	char c;
	int num=0;

	c=getchar();

	while(c!='\n'){
		if(c>='0'&&c<='9'){
			num=1;
			printf("%c",c);
		}
		else{
			if(num==1){
				putchar('\n');
				num=0;
			}
		}
		c=getchar();
	}
}


int main()
{
	char *p = NULL ;
	char str[100] ;
	cin.getline(str,100) ;
	p = str ;
	int len = strlen(str) ;
	for ( p = str ; p < str + len ; p++ )
	{
		if ( (int)*p >= 48 && (int)*p <= 57 )
		{
			if ( ((int)*(p - 1) < 48 || (int)*(p - 1) > 57) && p != str )
			{
				cout << endl ;
			}
			cout << *p ;
		}
	}
	cout << endl ;
	return 0 ;
}


int main()
{
	char shuru[500];
	cin.getline(shuru,500);
	int a = 0, i = 0;
	a = strlen(shuru);
	if(shuru[0] >= '0' && shuru[0] <= '9')
		cout << shuru[0];
	for(i = 0; i <= a - 1; i++)
	{
		if(i != 0)
		{
			if(shuru[i] >= '0' && shuru[i] <= '9')
				cout << shuru[i];
			if((shuru[i] < '0' || shuru[i] > '9') && (shuru[i - 1] >= '0' && shuru[i - 1] <= '9'))
				cout << endl;
		}
    }
	cout << endl;
	return 0;
}


int main(int argc, char* argv[])
{
	char str[40];
	int len,i,num=0;
	gets(str);
	len=strlen(str);
	for(i=0;i<=len-1;i++){
		if(str[i]>=48&&str[i]<=57){
			printf("%c",str[i]);
		}else if(i>0&&str[i-1]>=48&&str[i-1]<=57){
			printf("\n");
	        num+=1;
		}

	}
	if(str[len-1]>=48&&str[len-1]<=57){
			num+=1;
	}

	return 0;
}


//
//  main.cpp
//  hw
//
//  Created by ? ? on 12-12-19.
//  Copyright (c) 2012? ? ?. All rights reserved.
//

int number (char x)
{
    if (x>='0'&&x<='9') {
        return 0;
    }
    else
    {
        return 1;
    }
}
int main(int argc, const char * argv[])
{
    char str[LEN+3];
    gets(str);
    int len=strlen(str);
    str[len+1]='^';
    for (int i=0; i<len; i++) {
        if (number(str[i])) {
            str[i]=0;
        }
    }
    char *begin,*end;
    int k=0;
    while (str[k]==0) {
        k++;
    }
    begin=&str[k];end=&str[k+strlen(begin)];
    while (1) {
        cout<<begin<<endl;

        int i=1;
        while (*(end+i)==0&&*(end+i)!='^') {
            i++;
        }
        if (*(end+i)=='^') {
            break;
        }
        begin=end+i;
        end+=i+strlen(begin);
    }
    return 0;
}


int main()
{
	char a[1000];
	char *p[1000];
	int i;
	cin.getline(a,1000);
	for(i=0;i<strlen(a);i++)
	{
		if(a[i]>='0'&&a[i]<='9')
		{
			p[i]=&a[i];
		}
		else
		{
			p[i]=NULL;
		}
	}
	for(i=0;i<strlen(a);i++)
	{
		if(p[i]!=NULL)
		{
			cout<<*p[i];
		}
		else if(p[i+1]!=NULL)
		{
			cout<<endl;
		}
	}
	return 0;
}


int main()
{
	char *p = NULL;
	char a[31];
	cin.getline(a,31);
	int length = strlen(a), flag = 0;
	p = a;
	for (p = a; p < a + length; p++)
	{
		if ((*p - '0') >= 0 && (*p - '0') <= 9)
		{
			cout<<*p;
			flag = 0;
		}
		else if (flag == 0)
		{

			cout<<endl;
			flag = 1;
			continue;

		}
	}
	return 0;
}


int main()
{
	char *org,*p;
	int num=0;
	org=(char*)malloc(30*sizeof(char));
	gets(org);
	for(p=org;*p!='\0';p++)
	{
		if(isdigit(*p)==0)
		{
			if(num==0)printf("\n");
			num++;
		}
		else
		{
			num=0;
			printf("%c",*p);
		}
	}
	free(org);
}


int main()
{
 char string[30];
 gets(string);
 char *p=string;
 int clen,nolen=0;
 clen=strlen(string);
 for(int i=0;i<clen;i++)
 {
	 if(*(p+i)<'0'||*(p+i)>'9')
	 {
		 int ilen=0;
      if(*(p+i-1)<'0'||*(p+i-1)>'9')
	  { nolen++;ilen++;int jj=1;
	  while(1)
	  {
	   if(*(p+jj+i)<'0'||*(p+jj+i)>'9')
	   {nolen++;ilen++;jj++;}
	   else break;
	  }
	   for(int j=i;j<clen-nolen;j++)
	   {
	    *(p+j)=*(p+j+ilen);
	   }
	  }
	  else *(p+i)='\n';
	  }
 }
 string[clen-nolen]='\0';
 for(int j=0;j<clen;j++)
 {
  if((string[j]<'0'||string[j]>'9')&&(string[j]!='\n'))
  {
   string[j]='\0';break;
  }
 }
 cout<<string<<endl;
 return 0;
}


int main()
{
    char s[1000];
    int i,l;
    gets(s);
    l=strlen(s);
    for (i=0;i<l-1;i++)
    {
        if (isdigit(s[i]))
        printf("%c",s[i]);
        if (isdigit(s[i])&&isdigit(s[i+1])==0)
        printf("\n");
    }
    if (isdigit(s[l-1]))
    printf("%c",s[l-1]);
    return 0;
}


int main()
{
	int a,b,i,j,c,d=0,e,f,g;
	char *str,ch[30];
	str=ch;
	gets(str);
	a=strlen(str);
	for(i=0;i<a;i++)
	{
		if(*(str+i)>='0' && *(str+i)<='9') printf("%c",*(str+i));
		else if(*(str+i-1)<'0' || *(str+i-1)> '9'|| i==0) continue;
		else{ printf("\n");d++;}
	}
	return 0;
}


int pd(char *m)
{
	if(*m>='0'&&*m<='9') return(1);
	else return (0);
}
void main()
{
	char *p,*a;
	p=(char*)malloc(1000*sizeof(char));
	gets(p);
	for(a=p;*a!='\0';a++)
	{
       if(pd(a)) printf("%c",*a);
	   else if(pd(a-1)&&(pd(a)!=1))
		   printf("\n");
	   }
}


/*
 * 1000012795-????.cpp
 *
 *  Created on: 2010-12-29
 *      Author: Administrator
 */
int main()
{
	char str[31];
	char a[31];
	int len,i,j=0,num=0,sum=0;
	cin.getline(str,31);
	len=strlen(str);
	for(i=0;i<len;i++)
	{
		if(str[i]>='0'&&str[i]<='9')
		{
			a[j]=str[i];
			num=num+1;
			j=j+1;
		}
		if(str[i]<'0'||str[i]>'9')
		{
			for(j=0;j<num;j++)
			{
				if(a[j]!='0')
					break;
				sum=sum+1;
			}
			if(sum==num&&sum!=0)
			{
				cout<<"0"<<endl;
				num=0;
				sum=0;
			}
			else
			{
			for(j=sum;j<num-1;j++)
				cout<<a[j];
			cout<<a[num-1]<<endl;
			j=0;
			num=0;
			sum=0;
			}
		}
	}
	for(j=0;j<num;j++)
	{
		if(a[j]!='0')
			break;
		sum=sum+1;
	}
	if(sum==num&&sum!=0)
	    cout<<"0"<<endl;
	else
	{
	   for(j=sum;j<num-1;j++)
			cout<<a[j];
		cout<<a[num-1]<<endl;
	}
	return 0;
}


int main()
{
char c[30];
int i;

		for(i=0;i<30;i++)
		{scanf("%c",&c[i]);
		switch(c[i])
		{
		case '1':
		case '2':
	    case '3':
	    case '4':
	    case '5':
        case '6':
	    case '7':
		case '8':
         case '9':
	     case '0':
				printf("%c",c[i]);break;
				default :
					{switch(c[i-1])
			       {
		       case '1':
		        case '2':
               case '3':
	            case '4':
				case '5':
				case '6':
				case '7':
				case '8':
		          case '9':
			     case '0':
				printf("\n");break;
				   }
					}
			}}
	return 0;
		}


int main()
{
	char a[31];
	int i,len;
	cin.getline(a,31);
	len=strlen(a);
	for(i=0;i<len;i++){
		if(a[i]>=48&&a[i]<=57){
			cout<<a[i];
			if(a[i+1]<48||a[i+1]>57){
				cout<<endl;
			}
		}
	}
	return 0;
}


int main()
{
	char str[100];
	gets(str);
	int i,flag;
	for(i=0;str[i]!='\0';i++)
	{
		if((int)str[i]<58&&(int)str[i]>47)
		{
			cout<<str[i];
			flag=1;
		}
		else if(flag==1)
		{
			cout<<endl;
			flag=0;
		}
	}
	cout<<endl;
	return 0;
}


int number(char a);
int main()
{
	char c[30];
	int i,len,n;
	gets(c);
	len=strlen(c);
	n=0;
	while(number(c[n])==0){
	n++;
	}
	if(n==len-1)
		printf("%c",c[len-1]);
	if(n==len-2&&number(c[len-1])==1)
		printf("%c%c",c[len-2],c[len-1]);
	if(n==len-2&&number(c[len-1])==0)
		printf("%c",c[len-2]);
	if(n<len-2){
	printf("%c",c[n]);
	for(i=n+1;i<len;i++){
	if(number(c[i-1])==1&&number(c[i])==1)
		printf("%c",c[i]);
	if(number(c[i-1])==0&&number(c[i])==1)
		printf("\n%c",c[i]);
	}
	}
	return 0;
}
int number(char a){
	int m;
	if(a>='0'&&a<='9'){
	m=1;
	}else{
	m=0;
	}
	return m;
}


char a[35];
int main()
{
	gets(a);
	for(int i=0;i<strlen(a);i++){
		if(isdigit(a[i])!=0){
			if(isdigit(a[i+1])!=0)
				cout<<a[i];
			else
				cout<<a[i]<<endl;
		}
	}

}


int main() {
	char buf[32];
	gets(buf);
	int offset = 0;
	char c;
	while (offset < strlen(buf)) {
		c = *(buf+offset);
		if ('0' <= c && c <= '9') {
			cout << c;
		} else {
			cout << endl;
		}
		++offset;
	}
	return 0;
}


int main()
{
    char ch[50] ;
    cin.get( ch , 50 , '\n' ) ;
    int i = 0 ;
    int n = strlen( ch ) ;
    for( i = 0 ; i <= n - 1 ; i ++ )
    {
         if( ( int )ch[i] >= 48 && ( int )ch[i] <= 57 )
         cout << ch[i] ;
         else
         if( i > 0 )
         if( ( int )ch[i - 1] >= 48 && ( int )ch[i - 1] <= 57 )
         cout << endl ;
    }
return 0 ;
}


int main()
{
	char *p1;
	int i,j;
	char c=' ';
	p1=(char *)malloc(30*sizeof(char));
	gets(p1);
	for (i=0;i<(strlen(p1));i++)
	{
		if (isdigit(*(p1+i)))
			printf("%c",*(p1+i));
		else if ((isdigit(*(p1+i))==0)&&(isdigit(*(p1+i-1))!=0))
			printf("\n");
	}
	return 0;
}


void main()
{
	int n=0;
	char *p;
	p=(char *)malloc(sizeof(char)*31);
	gets(p);
	while(*p!='\0')
	{
		if(*p>='0'&&*p<='9')
		{
			if(n!=0)printf("\n%c",*p);
			else printf("%c",*p);
			n=0;
		}
		else n++;
		p++;
	}
}


int main()
{
    int i,len=0;
    char str[32],temp[32];
    char *ptr;
    cin.getline(str,31);
    ptr=str;
    for(;*ptr!='\0';++ptr)
    {
        if(isdigit(*ptr)) len++;
        else
        {
            memset(temp,0,sizeof(temp));
            if(len==0) continue;
            for(i=0;i<len;++i) temp[len-i-1]=*(ptr-i-1);
            len=0;
            cout<<atoi(temp)<<endl;
        }
    }
    if(len)
    {
        for(i=0;i<len;++i) temp[len-i-1]=*(ptr-i-1);
        cout<<atoi(temp)<<endl;
    }
    return 0;
}


int main() {
    char data[31];
    int n,i;
    gets(data);
    for(n=0;data[n]!='\0';n++);
    for(i=0;i<n;i++) {
        if(data[i]<='9'&&data[i]>='0') {
            printf("%c",data[i]);
        } else {
            printf("\n");
        }
    }
    return 0;
}


struct data
{
	char c;
	struct data *pt;
};//????????

struct data *create(void)//??????
{
	struct data *head,*p1,*p2;

	p1=p2=(struct data *)malloc(sizeof(struct data));//????
	head=p1;
	p1->c=getchar();

	for(;p2->c!='\n';)//?????
	{p1=(struct data *)malloc(sizeof(struct data));
	p1->c=getchar();
	p2->pt=p1;//???p2???????
	p2=p1;
	p2->pt=NULL;}

	return head;

}
void main()
{

	struct data *headi,*ptr;
	int flag=0;
	headi=create();

	for(ptr=headi;ptr!=NULL;ptr=ptr->pt)//????
		if('9'>=ptr->c&&'0'<=ptr->c) putchar(ptr->c),flag++;
		else
		{
			if(ptr->pt!=NULL)
				if('9'>=ptr->pt->c&&'0'<=ptr->pt->c&&flag!=0)
					putchar('\n');
		}
}


int main()
{
	char str[31];
	char *pointer=NULL;
	cin.getline(str,31);
	pointer=str;
	while(*pointer!=0)
	{
		if(*pointer>='0'&&*pointer<='9')
		{
			if(pointer==str||*(pointer-1)!='-')
			{
				while(*pointer>='0'&&*pointer<='9')
				{
					cout<<*pointer;
					pointer++;
				}
				cout<<endl;
			}
			else
			{
				while(*pointer>='0'&&*pointer<='9') pointer++;
			}
		}
		else pointer++;
	}
	return 0;
}


int main(){
char a[31];
cin.getline(a,31);
int d,i;
d=strlen(a);
int b[100];
memset(b,-1,sizeof(b));
int num=0;
int sum=0;
for(i=0;i<d;i++){
	if((a[i]<58)&&(a[i]>47)){
		sum=sum*10+(int)(a[i]-48);
		b[num]=sum;
	}
	else {
		num++;
		sum=0;
	}
}
for(i=0;i<100;i++){
	if(b[i]>=0){
	cout<<b[i]<<endl;}
	else continue;
}
return 0;}


int main()
{
	char c[30];
	int i,n,shi,zhong,m,l;
	gets(c);
	n=strlen(c);
	for(i=0;i<n;i++)
	{
		if(c[i]<='9'&&c[i]>='0')
		{
			shi=i;
			for(l=i;l<n;l++)
			{
				if(c[l]>'9'||c[l]<'0')
				{
					zhong=l-1;
					break;
				}
				if(l==n-1)
					zhong=n-1;
			}
			for(m=shi;m<zhong;m++)
			{
				printf("%c",c[m]);
			}
			printf("%c\n",c[zhong]);
			i=zhong;
		}
	}
	return 0;
}


int main()
{
	char str[31];
	gets(str);

	char * p=str;

	int flag=0;
	while(p<str+strlen(str))
	{
		if((*p>='0')&&(*p<='9'))
			{
				cout<<*p;
				flag=1;
		    }
		else
			{
				if(flag==1)
				   cout<<endl;
				flag=0;
		     }
		p++;
	}

	return 0;
}


/*
 * tqsz.cpp
 *
 *  Created on: 2010-12-31
 *      Author: dell
 */
int main(){
	int s,i,longs;
	char zfc[50];
	cin.getline(zfc,50);
	longs=strlen(zfc);
	for(i=0;i<longs;i++){
		if(zfc[i]>47&&zfc[i]<58){
		s=zfc[i]-48;
			cout<<s;
		}
		else
			cout<<endl;
	}
}


int main()
{
	char str[200],*point=str;
	cin.getline(str,150);
	for(;point<=str+strlen(str)-1;point++)
	{
		if(*point>='0'&&*point<='9')
		{
			while(*point>='0'&&*point<='9')
			{
				cout<<*point;
				point++;
			}
			cout<<endl;
		}
	}
	return 0;
}


int main()
{
	char buff[50] = {0};
	cin.getline(buff,50);
	int len = strlen(buff);
	int num = 0;
	for (int i = 0 ; i < len ; i ++)
	{
		if (buff[i] >= '0' && buff[i] <= '9')
		{
			num = 10 * num + buff[i] - '0';
			if (buff[i + 1] == '\0')
			{
				cout << num << endl;
			}
		}
		else
		{
			if (buff[i - 1] >= '0' && buff[i - 1] <= '9')
			{
				cout << num << endl;
				num = 0;
			}
		}
	}
	return 0;
}