import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();

		int T = sc.nextInt();
		for (int t = 0; t < T; t++) {
			int n = sc.nextInt();
			long a = sc.nextLong();

			boolean pre = false;
			boolean now = false;
			long max = -2 * 1000000000;
			long sum = 0;

			if (a > 0) {
				pre = true;
			}

			max = a;

			for (int i = 0; i < n - 1; i++) {
				a = sc.nextLong();
				if (a > 0) {
					now = true;
				} else {
					now = false;
				}

				if (now == pre) {
					max = Math.max(max, a);
				} else {
					sum += max;
					max = a;
					pre = now;
				}
			}
			sb.append(sum + max);
			sb.append("\n");
		}
		System.out.print(sb.toString());
	}
}
