import java.util.Scanner;

public class As_1343C {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scanner = new Scanner(System.in);
		int t = scanner.nextInt();
		for (int i = 0; i < t; i++) {
			int n = scanner.nextInt();
			double[] x;
			x = new double[n];
			double sum = 0;
			for (int j = 0; j < n; j++) {
				x[j] = scanner.nextDouble();
			}
			int count = 1;
			double maxPos = 0;
			double maxNeg = -1000000000;
			if (x[0] > 0)
				maxPos = x[0];
			else
				maxNeg = x[0];
			do {
				// boolean alt = false;
				if (x[count] * x[count - 1] < 0) {
					if (x[count] < 0) {

						sum += maxPos;
						maxPos = 0;
						maxNeg = x[count];
						// alt = true;
						// System.out.println(sum);
						// System.out.println(maxPos);
					}

					else {
						// System.out.println(maxNeg);
						sum += maxNeg;
						maxPos = x[count];
						maxNeg = -1000000000;
						// alt = true;
					}
				} else {
					if (x[count] > maxPos) {
						maxPos = x[count];
					}
					if (x[count] > maxNeg && x[count] < 0) {
						maxNeg = x[count];
					}

				}
				count++;

				// System.out.println(sum);
			} while (count < n);
			if (x[count - 1] < 0)
				sum += maxNeg;
			else
				sum += maxPos;
			System.out.println(sum);
		}
		scanner.close();
	}
}
