import java.util.*;


public class C1343 {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int t = in.nextInt();
		while (t-- > 0) {
			int n = in.nextInt();
			int[] array = new int[n + 1];
			for (int i = 1; i <= n; i++) {
				array[i] = in.nextInt();
			}
			int x = array[1];
			List<Long> list = new ArrayList<>();
			for (int i = 2; i <= n; i++) {
				if (array[i] < 0 && x < 0) {
					x = Math.max(x, array[i]);
				} else if (array[i] > 0 && x > 0) {
					x = Math.max(x, array[i]);
				} else {
					list.add((long) x);
					x = array[i];
				}
			}
			list.add((long) x);
			System.out.println(list.stream().reduce(0L, (sub, y) -> sub + y));
		}
	}
}