import java.util.*;

public class Main{
//public class P636C{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);

		int test = scan.nextInt();

		while(test>0){
			int n = scan.nextInt();

			int[] a = new int[n];
			int[] sum = new int[n];
			long ans = 0;

			boolean cur = true; //true = pos 
			boolean prev = true;

			int count = 0; 

			for(int i=0; i<n; i++){
				a[i] = scan.nextInt();

				if(i==0){
					if(a[i]>0){
						cur = true;
						prev = false;
					}
					else{
						cur = false;
						prev = true;
					}
				}
				else{
					if(a[i]>0){
						cur = true;
					}
					else{
						cur = false;
					}
				}
				

				if(cur==prev){
					ans -= (long)sum[count-1];
					sum[count-1] = Math.max(sum[count-1], a[i]);
					ans += (long)sum[count-1];
					
				}
				else{
					
					sum[count] = a[i];
					ans += (long)a[i];
					count++;
				}

				prev = cur;

				///System.out.println(ans);

			}

			System.out.println(ans);
			test--;
		}
	}
}