import java.util.ArrayList;
import java.util.Scanner;

public class maxalt {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		int t=scn.nextInt();
		for(int i=0;i<t;i++) {
			int size=scn.nextInt();
			int[] arr=new int[size];
			for(int j=0;j<size;j++) {
				arr[j]=scn.nextInt();
			}
			for(int vidx=0;vidx<size;vidx++) {
				maxsum(arr,vidx);
			}
			System.out.println(arsum);
			int ans=Integer.MIN_VALUE;
			for(int val:arsum) {
				if(val>ans) {
					ans=val;
				}
			}
			System.out.println(ans);
		}
	}
	static ArrayList<Integer> arsum=new ArrayList<>();
	public static int maxsum(int[] arr,int vidx) {
		if(vidx>=arr.length) {
			arsum.add(0);
			return 0;
		}
		for(int i=vidx+1;i<arr.length;i++) {
			int s=arr[vidx]*arr[i];
			if(s<0) {
				int newsum=arr[vidx]+maxsum(arr,i);
				arsum.add(newsum);
				return newsum;
			}
			//return arr[vidx];
		}
		arsum.add(arr[vidx]);
		return arr[vidx];
	}
}
