import java.util.*;

public class C1343C {
	public static boolean checkSign(int a, int b) {
		if (a > 0 && b > 0) {
			return true;
		} else if (a < 0 && b < 0) {
			return true;
		} else {
			return false;
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		for (int i = 0; i < t; i++) {
			int n = sc.nextInt();
			int array[] = new int[n];
			int alternate = 1;
			for (int k = 0; k < n; k++) {
				array[k] = sc.nextInt();
				if (k >= 1) {
					if ((array[k] > 0 && array[k - 1] < 0) || (array[k] < 0 && array[k - 1] > 0)) {
						alternate++;
					}

				}
			}
			long[] dp = new long[alternate];
			dp[0] = array[0];
			int x = 0;
			// System.out.println(alternate);
			for (int k = 1; k < n; k++) {
				if (x == 0) {
					if (checkSign(array[k], array[k - 1])) {
						dp[x] = Math.max(dp[x], Math.max(array[k], array[k - 1]));
						continue;
					} else if (!checkSign(array[k], array[k - 1])) {
						x++;
						dp[x] = dp[x - 1] + array[k];
						continue;
					}
				} else if (x > 0) {
					if (!checkSign(array[k], array[k - 1])) {
						x++;
						dp[x] = dp[x - 1] + array[k];
					} else if (checkSign(array[k], array[k - 1])) {
						dp[x] = dp[x - 1] + Math.max(dp[x],Math.max(array[k], array[k - 1]));
					}
				}

			}
			System.out.println(dp[alternate - 1]);
		}

	}
}
