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());
			long[] a = new long[n];
			for (int j = 0; j < a.length; j++) {
				a[j]= Long.parseLong(st.nextToken());
			}
			long ans=0;
			ArrayList<Long> arr = new ArrayList<Long>();
			for (int j = 0; j < a.length; j++) {
				if(j>0 && ((a[j]>0&&a[j-1]>0)||(a[j]<0&&a[j-1]<0)))
				{
					long temp=arr.remove(arr.size()-1);
					arr.add(Math.max(temp,a[j]));
				}
				else
				{
					arr.add(a[j]);
				}
			}
			for (int j = 0; j < arr.size(); j++) {
				ans+=arr.get(j);
			}
			pw.println(ans);
		}
		pw.close();
	}
}