import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		while(t-- > 0){
			int n = sc.nextInt();
			long[] a = new long[n];
			for(int i = 0; i < n; i++){
				a[i] = sc.nextLong();
			}
			
			/**
			 * 把连续的相同符号的数看成一块，把块内最大值累加到答案
			 */
			
			long posMax = -1;
			long negMax = -1000000001;
			long sum = 0;
			
			if(a[0] > 0){
				posMax = Math.max(a[0], posMax);
			}else{
				negMax = Math.max(a[0], negMax);
			}
			
			for(int i = 1; i < n; i++){
				if(a[i-1] > 0){
					if(a[i] > 0){
						posMax = Math.max(a[i-1], a[i]);
					}else{
						sum += Math.max(a[i-1], posMax);
						posMax = -1;
					}
				}else{
					if(a[i] < 0){
						negMax = Math.max(a[i-1], a[i]);
					}else{
						sum += Math.max(a[i-1], negMax);
						negMax = -1000000001;
					}
				}
			}
			
			if(a[n-1] > 0){
				sum += Math.max(a[n-1], posMax);
			}else{
				sum += Math.max(a[n-1], negMax);
			}
			
			System.out.println(sum);
		}
	}
}