import java.io.*;
import java.util.*;  
public class main {	
	public static void main(String[] args) throws NumberFormatException, IOException
	{
		BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw= new PrintWriter(System.out);
		int t = Integer.parseInt(br.readLine());
		for (int i = 0; i < t; i++) {
			int n =Integer.parseInt(br.readLine());
			StringTokenizer st = new StringTokenizer(br.readLine());
			int[] a = new int[n];
			for (int j = 0; j < a.length; j++) {
				a[j]= Integer.parseInt(st.nextToken());
			}
			long ans=0;
			int element=a[0];
			for (int j = 1; j < a.length; j++) {
				if((element>0 && a[j]>0)||(element<0 && a[j]<0))
				{
					element=Math.max(element, a[j]);
				}
				else
				{
					ans+=element;
					element=a[j];
				}
				if(j==a.length-1)ans+=element;
			}
			pw.println(ans);
		}
		pw.close();
	}
}