import java.util.*;
import java.io.*;

public class tr0 {
	static PrintWriter out;
	static StringBuilder sb;
	static int mod = 1000000007;
	static long inf = (long) 1e18 + 1;
	static int[] col;
	static ArrayList<Integer>[] ad;
	static long[][][] memo;
	static HashSet<Integer> h;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		int t = sc.nextInt();
		while (t-- > 0) {
			int n = sc.nextInt();
			int[] a = sc.nextArrInt(n);
			if (n == 1) {
				out.println(a[0]);
				continue;
			}
			int ln = 0;
			long sumn = 0;
			int lp = 0;
			long sump = 0;
			ArrayList<Integer> com = new ArrayList<>();
			for (int i = 0; i < n - 1; i++) {
				int max = 0;
				int mai = Integer.MIN_VALUE;
				if (a[i] > 0)
					while (i < n - 1 && a[i]>0&&a[i + 1] >0) {
						max = Math.max(a[i], a[i + 1]);
						i++;
					}
				else
					while (i < n - 1 && a[i] <0 && a[i + 1] <0) {
						mai = Math.max(a[i], a[i + 1]);
						i++;
					}
				if (max != 0)
					com.add(max);
				else if (mai != Integer.MIN_VALUE)
					com.add(mai);
				else
					com.add(a[i]);
			}
			if (a[n - 1] >0 && a[n - 2] <0)
				com.add(a[n - 1]);
			if (a[n - 1] <0 && a[n - 2] >0)
				com.add(a[n - 1]);
		   for(int i=0;i<com.size();i++)
			   sumn+=com.get(i);
		   out.println(sumn);
		}
		out.flush();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public int[] nextArrInt(int n) throws IOException {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextArrLong(int n) throws IOException {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}