import java.util.Scanner;

public class AlternatingSubsequence {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner str = new Scanner(System.in);
		int t = str.nextInt();
		while(t-- > 0) {
			int n = str.nextInt();
			int a[] = new int[n];
			for(int i = 0; i < n; i++) {
				a[i] = str.nextInt();
			}
			long sum = 0;
			int temp = a[0];
			for(int i = 1; i < n; i++) {
//				System.out.println("a["+i+"] = "+a[i]);
				if(a[i]>0 && a[i-1]>0) {
					if(a[i] >= a[i-1]) {
						temp = a[i];
					}else {
						temp = a[i-1];
					}
				}else if(a[i]<0 && a[i-1]<0) {
					if(a[i] >= a[i-1]) {
						temp = a[i];
					}else {
						temp = a[i-1];
					}
				}else {
					sum += temp;
					temp = a[i];
				}
//				System.out.println("temp["+i+"] = "+temp);
			}
			sum += temp;
			System.out.println(sum);
		}
	}

}
