import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Random;
import java.util.StringTokenizer;

public class ProblemB {
	public static void main(String [] args) throws IOException{
		solve();
}



	public static void solve() throws IOException {
		Scanner sc = new Scanner(System.in);
		int t=sc.nextInt();
		all:for(int c=0;c<t;c++) {
			int n=sc.nextInt();
			if(n==1) {
				System.out.println(sc.nextLong());
				continue all;
			}
			long arr[] = new long[n];
			int start [] = new int[n];	int end [] = new int[n];
			for(int i=0;i<n;i++) {
				arr[i]=sc.nextLong();
			}
			start[0]=0;
			char lastSeen;
			if(arr[0]<0) {
			lastSeen ='N';}
			else {
				 lastSeen ='P';
			}
			int k=0;
			for(int i=1;i<n;i++) {
				if(lastSeen== 'N' && arr[i]<0) {
					end[k]=i-1;
					k++;
					start[k]=i;
				}else if(lastSeen=='P' && arr[i]>0) {
					end[k]=i-1;
					k++;
					start[k]=i;
				}else if(lastSeen=='N' && arr[i]>0) {
					lastSeen='P';
				}else {
					lastSeen='N';
				}
			}
			end[k]=arr.length-1;
			//System.out.println("Start arr" + Arrays.toString(start));
			//System.out.println("end arr" + Arrays.toString(end));
			int maxDiff=Integer.MIN_VALUE;
			for(int i=0;i<start.length;i++) {
				if(end[i]-start[i]>maxDiff) {
					maxDiff=end[i]-start[i];
				}
			}
			long maxSum=Long.MIN_VALUE;
			long currSum=0;
			//System.out.println("MaxDiff"+maxDiff);
			for(int i=0;i<start.length;i++) {
				currSum=0;
				if(end[i]-start[i]==maxDiff) {
					for(int j=start[i];j<=end[i];j++) {
						currSum+=arr[j];
						//System.out.println("CurrSum"+currSum);
					}
					if(currSum>maxSum) {
						maxSum=currSum;
					}
				}
			}
			System.out.println(maxSum);
			
			
		}
	
	
	
	
	}
	
	
	
	
	
	
	
	
	static void shuffle(int[] a)
	{
		int n = a.length;
		for(int i = 0; i < n; i++)
		{
			int r = i + (int)(Math.random() * (n - i));
			int tmp = a[i];
			a[i] = a[r];
			a[r] = tmp;
		}
	}
	static class Pair{
		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + end;
			result = prime * result + start;
			return result;
		}
		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			Pair other = (Pair) obj;
			if (end != other.end)
				return false;
			if (start != other.start)
				return false;
			return true;
		}
		int start;
		int end;
		public Pair(int s,int e) {
			start=s;
			end=e;
		}
	}


	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens()) 
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {return Long.parseLong(next());}

		public String nextLine() throws IOException {return br.readLine();}

		public double nextDouble() throws IOException
		{
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if(x.charAt(0) == '-')
			{
				neg = true;
				start++;
			}
			for(int i = start; i < x.length(); i++)
				if(x.charAt(i) == '.')
				{
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				}
				else
				{
					sb.append(x.charAt(i));
					if(dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg?-1:1);
		}

		public boolean ready() throws IOException {return br.ready();}
	}

}