import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class C {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int t = scanner.nextInt();
		
		for (int i = 0; i < t; i++) {
			int n = scanner.nextInt();
			List<Integer> arr = new ArrayList<>();
			for (int j = 0; j < n; j++) {
				arr.add(scanner.nextInt());
			}
			
			if (n == 1) {
				System.out.println(arr.get(0));
			} else {
				int pre = arr.get(0);
				int max = pre;
				long sum = 0;
				for (int j = 1; j < n; j++) {
					int now = arr.get(j);
					long num = pre * now;
					if (num > 0) {
						max = Math.max(max, now);
					} else {
						sum += max;
						max = now;
					}
					pre = now;
				}
				sum += max;
				System.out.println(sum);
			}
		}
		
		scanner.close();
	}
}