import java.util.Scanner;

public class alternatingSubsequence {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder ans = new StringBuilder();
		int T = sc.nextInt();
		while (--T >= 0) {
			int n = sc.nextInt(), a[] = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = sc.nextInt();
			}
			boolean pos = false;
			if (a[0] > 0)
				pos = true;
			int max = Integer.MIN_VALUE;
			long sum = 0;
			for (int j = 0; j < n;) {
				if ((!pos && a[j] < 0) || (pos && a[j] > 0)) {
					max = Integer.max(max, a[j]);
					j++;
				} else {
					pos = !pos;
					sum += max;
					max = Integer.MIN_VALUE;
				}
			}
			if (max != Integer.MAX_VALUE)
				sum += max;
			ans.append(sum + "\n");
		}
		System.out.println(ans);
		sc.close();
	}
}
