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

public class Prob636C {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		ArrayList<Integer> a = new ArrayList<Integer>();
		ArrayList<Integer> newseq = new ArrayList<Integer>();
		int t,n,k,max=0,out=0,sum=0,entered=0;
		t=s.nextInt();
		while(t-->0) {
			n=s.nextInt();
			for(int i=0;i<n;i++) {
				a.add(i, s.nextInt());
			}
			k=0;
			while(k<n) {
				max=a.get(k);
				while(a.get(k)>0) {
					if(max<a.get(k)) {
						max=a.get(k);
					}
					k++;
					entered=1;
					if(k>=n) {
						out=1;
						break;
					}
					entered=1;
				}
				if(entered==1) {
					newseq.add(max);
					entered=0;
				}
				if(out==1) {
					out=0;
					break;
				}
				max=a.get(k);
				while(a.get(k)<0) {
					if(max<a.get(k)) {
						max=a.get(k);
					}
					k++;
					entered=1;
					if(k>=n) {
						out=1;
						break;
					}	
				}
				if(entered==1) {
					newseq.add(max);
					entered=0;
				}
				if(out==1) {
					out=0;
					break;
				}
			}
			for(int i=0;i<newseq.size();i++) {
				sum+=newseq.get(i);
			}
			System.out.println(sum);
			sum=0;
			newseq.removeAll(newseq);
		}
}

	}
