#include <stdio.h>


int main () {

	int dataset=0;
	int dataset_num=0;
	int input=0;
	int count=0;

	int point[1000]={};
	int max=0;
	int sma=0;
	int cul=0;


	


	while(1){

		scanf("%d",&dataset);

		if(dataset ==0){
			break;
		}
		while( dataset != 0 ){
			count=0;

			while(1){
				scanf("%d",&point[count]);
				
				

				if(count==0){
					max = point[count];
					sma = point[count];
				}

				if(max < point[count]){
					max = point[count];
				}
				if(sma > point[count]){
					sma = point[count];
				}
				
				cul += point[count];
				if(point[count] == 0 ){
					//printf("input finish\n");
					break;
				}
				count++;

			}
			//printf("%d\n",count );
			cul -= max;
			cul -= sma;
			//printf("%d\n",count );
			cul = cul/(count-2);
			printf("%d\n",cul );
			max=0;
			sma=0;
			cul=0;


			

			dataset--;
			input++;

		}
	}
		


	return 0;
}