
import java.util.*;
import java.io.*;
public class A1394
{
	public static void process()throws IOException
	{
		int n=I();
		int a[]=Ai(n);int min=Integer.MIN_VALUE;int max=Integer.MIN_VALUE;
		long sum=0;
		for(int i=0;i<n-1;i++)
			{
			if(a[i]<0 && a[i+1]<0)
			{
			
				max=Math.max(max,a[i]);
				max=Math.max(max,a[i+1]);
			//pn("NEGATib\t"+max);
						
			}
			else
			if(a[i]>=0 && a[i+1]>=0)
			{
				max=Math.max(max,a[i]);
				max=Math.max(max,a[i+1]);
				//pn("post\t"+max);
			}
			else
			{
				//pn(max);
				if(max==Integer.MIN_VALUE)
				{
					max=a[i];
				}
				sum=sum+max;
				
				max=Integer.MIN_VALUE;
			}
			
			}
		if(a[n-1]>0 && a[n-2]<0 || a[n-1]<0 && a[n-2]>0)
		{
			sum=sum+a[n-1];
		}
		else
		{
			sum=sum+max;
		}
		pn(sum);
	}
		
	
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
	
	
	
	
	
	
	
	
	
	
	static Scanner sc = new Scanner(System.in);
	static PrintWriter out = new PrintWriter(System.out);
	static void pn(Object o){out.println(o);out.flush();}
	static void p(Object o){out.print(o);out.flush();}
	static void pni(Object o){out.println(o);System.out.flush();}
	static int I() throws IOException{return sc.nextInt();}
	static long L() throws IOException{return sc.nextLong();}
	static double D() throws IOException{return sc.nextDouble();}
	static String S() throws IOException{return sc.next();}
	static char C() throws IOException{return sc.next().charAt(0);}
	static int[] Ai(int n) throws IOException{int[] arr = new int[n];for (int i = 0; i < n; i++)arr[i] = I();return arr;}
	static String[] As(int n) throws IOException{String s[] = new String[n];for (int i = 0; i < n; i++)s[i] = S();return s;}
	static long[] Al(int n) throws IOException {long[] arr = new long[n];for (int i = 0; i < n; i++)arr[i] = L();return arr;}
//	*--------------------------------------------------------------------------------------------------------------------------------*//
	static class AnotherReader {BufferedReader br;StringTokenizer st;AnotherReader() throws FileNotFoundException {br = new BufferedReader(new InputStreamReader(System.in));}
	AnotherReader(int a) throws FileNotFoundException {br = new BufferedReader(new FileReader("input.txt"));}
	String next() throws IOException{while (st == null || !st.hasMoreElements()) {try {st = new StringTokenizer(br.readLine());} catch (IOException e) {e.printStackTrace();}}return st.nextToken();}
	int nextInt() throws IOException {return Integer.parseInt(next());}
	long nextLong() throws IOException {return Long.parseLong(next());}
	double nextDouble() throws IOException {return Double.parseDouble(next());}
	String nextLine() throws IOException {String str = "";try {str = br.readLine();} catch (IOException e) {e.printStackTrace();}return str;}}
	public static void main(String[] args)throws IOException{try{boolean oj=true;if(oj==true)
	{AnotherReader sk=new AnotherReader();PrintWriter out=new PrintWriter(System.out);}
	else
	{AnotherReader sk=new AnotherReader(100);out=new PrintWriter("output.txt");}
	long T=L();while(T-->0)
	{process();}out.flush();out.close();}catch(Exception e){return;}}}
//*-----------------------------------------------------------------------------------------------------------------------------------*//
	


