import java.util.*;
import java.lang.*;
import java.io.*;
 
public class Codechef  {
	
	public static void main (String[] args) throws java.lang.Exception {	
		Scanner scn = new Scanner(System.in);
		long t = scn.nextLong();
				
		while(t-->0) {
			
			long n = scn.nextLong();
			
			
			long[] a = new long[(int)n];
			for(int i = 0;  i < n; i++) {
				a[i] = scn.nextLong();
			}
			
			
			
			
			long max = Long.MIN_VALUE;
			long sum = 0;
//			boolean flag = true;
			
			int i = 0;
			
			while(i < n) {
//				flag = true;
				max = a[i];
				while(i < n-1) {
					if(a[i]*a[i+1] > 0) {
						max = Math.max(a[i], a[i+1]);
					}
					else {
						i++;
						break;
					}
			
									
					i++;
				}
				
				if(i == n-1) {
					if(n == 1 || a[i]*a[i-1] > 0) {
						sum+=max;
					}
					else {
						sum+=a[i];
						sum+=max;
					}
					break;
				}
				
				sum+=max;
				
			}
			
			
			System.out.println(sum);
			
			
			
			
			
			
		}
	}
}








