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

public class AlternatingSubsequence {
	private static final FastReader in = new FastReader();
	private static final PrintWriter out = new PrintWriter(System.out);
	
	public static void main(String[] args) {
		Solver sol = new Solver();
		int tt = 1;
		for (int qq = in.nextInt(); tt <= qq; ++tt)
			sol.solve(tt);
		out.close();
	}
	
	private static final class Solver {
		public void solve(int testCase) {
			int n = in.nextInt();
			int[] a = new int[n];
			for (int i = 0; i < n; ++i)
				a[i] = in.nextInt();
			long ans = 0;
			for (int i = 0; i < n; ++i) {
				int first = a[i];
				int j = i;
				for (j = i; j < n && (a[i] > 0) == (a[j] > 0); ++j)
					first = Math.max(first, a[j]);
//				out.print(" " + first);
				ans += first;
				i = j - 1;
			}
//			out.println();
			out.println(ans);
		}
	}
	
	private static final class FastReader {
		private BufferedReader br;
		private StringTokenizer st;
		
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in), 1 << 16);
			st = null;
		}
		
		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
}