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

public class Ana {
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int t=sc.nextInt();
		final int INF= (int)(-10e9); 
		while(t-->0) {
			int n=sc.nextInt();
			long sum=0;
			int[] arr= new int[n];
			for(int i=0;i<n;i++)
				arr[i]=sc.nextInt();
			boolean neg=arr[0]<0;
			int max=INF;
//			System.out.println(max);
			for(int i=0;i<n;i++) {
				if(neg) {
					if(arr[i]<0)
						max=Math.max(max, arr[i]);
					else {
						sum+=max;
						max=INF;
						neg=false;
						i--;
					}
				}
				else {
					if(arr[i]>0)
						max=Math.max(max, arr[i]);
					else {
						sum+=max;
						max=INF;
						neg=true;
						i--;
					}
				}
			}
			sum+=max;
			out.println(sum);	
		}
		out.close();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

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

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

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

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

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

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