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

public class Codeforces {
	
	static void sort(int[] ar) {
		ArrayList<Integer> al=new ArrayList<>();
		for (int i=0;i<ar.length;i++) al.add(ar[i]);
		Collections.sort(al);
		for (int i=0; i<ar.length; i++) ar[i]=al.get(i);
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int t=sc.nextInt();
		while(t-->0)
		{
			int n=sc.nextInt();
			int a[]=new int[n];
			for(int i=0;i<n;i++)
				a[i]=sc.nextInt();
			long s=0;
			for(int i=0;i<n;)
			{
				if(a[i]>0)
				{
					int max=0;
					while(i<n && a[i]>0)
					{
						max=Math.max(max, a[i]);
						i++;
					}
					s+=max;
				}
				else
				{
					int max=Integer.MIN_VALUE;
					while(i<n &&a[i]<0)
					{
						max=Math.max(max, a[i]);
						i++;
					}
					s+=max;
				}
			}
			System.out.println(s);
		}

	}

}