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

public class cf6363C {
	public static void main(String[] args) throws Exception {
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int t = Integer.parseInt(br.readLine());
		
		while(t-- > 0)
		{
			int n = Integer.parseInt(br.readLine());
			String[] str = br.readLine().split(" ");
			long[] arr = new long[n];
			for(int i=0;i<n;i++) arr[i] = Long.parseLong(str[i]);
			
			long max_pos = Long.MIN_VALUE;
			long max_neg = Long.MIN_VALUE;
			List<Long> h = new ArrayList<>();
			
			for(int i=0;i<n;i++)
			{
				if(arr[i] < 0)
				{
					if(arr[i] > max_neg)
					{
						max_neg = arr[i];
						h.add(arr[i]);
					}
				}
				if(arr[i] > 0)
				{
					if(arr[i]>max_pos)
					{
						max_pos = arr[i];
						h.add(arr[i]);
					}
				}
			}
			
			long sum=0;
			for(int i=0;i<h.size();i++)
			{
				sum+=h.get(i);
			}
			
			System.out.println(sum);
		}
	}
}
