import java.util.*;
import java.io.*;


public class Main {

	public static void main(String []args){
		Scanner scan=new Scanner(System.in);
		int t=scan.nextInt();
		while (t-->0) {
			int N=scan.nextInt();
			int[] arr1=new int[N];
			for (int i=0;i<N;i++) {
				arr1[i]=scan.nextInt();
			}
			ArrayList<Integer> arr=new ArrayList<>();
			int i=0;
			while (i<N) {
				int pos=0;
				while (i<N && arr1[i]>0) {
					pos=Math.max(pos, arr1[i]);
					i++;
				}
				arr.add(pos);
				int neg=Integer.MIN_VALUE;
				while (i<N && arr1[i]<0) {
					neg=Math.max(neg, arr1[i]);
					i++;
				}
				if (neg>Integer.MIN_VALUE) {
					arr.add(neg);
				}
			}
			long ans=0;
			for (int el:arr) {
				ans+=el;
			}
			System.out.println(ans);	
		}
		

	}
}