#include <stdio.h>


int main () {

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

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


	scanf("%d",&dataset);
	dataset_num = dataset;

	while( dataset != 0 ){
		count=0;

		while(1){
			scanf("%d",&point[count]);
			if(point[count] == 0 ){
				//printf("input finish\n");
				break;
			}
			

			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];
			count++;

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


		printf("%d\n",cul );

		dataset--;
		input++;

	}
		


	return 0;
}