import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class C {

	public static class pair implements Comparable<pair> {
		int id;
		int ans;

		pair(int x, int y) {

			id = x;
			ans = y;

		}

		public pair() {

		}

		public int compareTo(pair o) {
			// TODO Auto-generated method stub

			return this.id - o.id;
		}
	}

	static int mod = (int) 1e9 + 7;
	static ArrayList<Integer> gr[];
	static int ar[];
	static Scanner sc = new Scanner(System.in);
	static int pri[] = new int[(int) 1e6 + 5];
	static StringBuilder out = new StringBuilder();
	static int dp[];

	public static void main(String[] args) throws IOException {
		int t = sc.nextInt();

		while (t-- > 0) {

			int n=sc.nextInt();
			ar=new int[n];
			for(int i=0;i<n;i++) {
				ar[i]=sc.nextInt();
				
			}
			boolean pre=true,cu=true;
			long sum=0;
			long max=Long.MIN_VALUE;
			for(int i=0;i<n;i++) {
				if(i==0) {
					if(ar[i]<0) {
						pre=false;
						cu=false;
						
					}
					else {
						pre=true;
						cu=true;
					}
					sum+=ar[i];
				}
				else {
					if(ar[i]<0)cu=false;
					else cu=true;
					if(pre==cu) {
						
					
						max=Math.max(max, sum);
						sum=ar[i];
					}
					else {
						sum+=ar[i];
					}
					pre=cu;
				}
			}
			max=Math.max(max, sum);
			out.append(max+"\n");
			
		}
		System.out.println(out);

	}

}
