int main()
{
    int n,i,j;
    int m,a,a0,time,result,k;
    //freopen("test2.in","r",stdin);
    scanf("%d",&n);
    
    for(i=0;i<n;i++)
    {
    	scanf("%d",&m);
    	time=0;
    	a0=0;
    	for(j=1;j<=m;j++)
    	{
	    	scanf("%d",&a);
	    	time=time+(a-a0)+3;//a-a0??????????????????????????????3????????????3???? 
	    	if(time>=60)
	    	{
	    		for(k=j+1;k<=m;k++)//??for ???????????????????????????? 
	    			scanf("%d",&a);
	    	    break;	
	    	}
 	        a0=a;
	    }
	    if(time<60)//?j<=m?????? 
	    {
    		result=60-3*m;//???????????????????3??????1???60?????60?????????m????????3*m?? 
    	}
    	else
    	{
	    	if(time==60)//?j????????j?????3???????60??????????????????????60????????60-j*3? 
	    	{
	    		result=60-j*3;
	    	}
	    	else
	    	{
	    		if(time-3<=60)//?j????60????????????3????????60?? 
	    		{
		    		result=time-3-(j-1)*3;//?j?????????????????????j-1???????? 
		    	}
	    		else result=60-(j-1)*3;//?j??????????60??? 
	    	}
	    }
	    printf("%d\n",result);
    }
	return 0;
}