
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class a {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);
		StringTokenizer st = new StringTokenizer(br.readLine());
		int te = Integer.parseInt(st.nextToken());

		while (te-- > 0) {
			int n = Integer.parseInt(br.readLine());
			int a[] = new int[n];
			st = new StringTokenizer(br.readLine());
			int p = -1;
			int max = 0;
			int min = 0;
			long sum = 0;
			int s = 0;
			for (int i = 0; i < a.length; i++) {
				a[i] = Integer.parseInt(st.nextToken());
				if (a[i] > 0) {
					if (p == 0)
						s++;
					p = 1;
				} else {
					if (p == 1)
						s++;
					p = 0;

				}
				if (p == 1) {
					max = Math.max(max, a[i]);
					sum += min;
					min = 0;
				} else {
					if (min != 0)
						min = Math.max(min, a[i]);
					else
						min = a[i];
					sum += max;
					max = 0;
				}
			}
			sum+=max+min;
			 pw.println(sum);
		}
		pw.flush();
	}

	public static long bs(long x) {
		long lo = 0;
		long hi = (long) 1e9;
		long ans = -1;
		while (lo <= hi) {
			long mid = (lo + hi) / 2;
			long sum = mid * (mid + 1);
			if (sum <= x) {
				ans = mid;
				lo = mid + 1;
			} else
				hi = mid - 1;
		}
		return ans;
	}

	static class pair implements Comparable<pair> {
		long x, y;

		public pair(long l, long m) {
			x = l;
			y = m;
		}

		@Override
		public String toString() {
			return "(" + x + " " + y + ")";
		}

		@Override
		public int compareTo(pair o) {
			// TODO Auto-generated method stub
			return (int) (x - o.x);
		}
	}
}