import java.util.*;
public class Solution {
public static void main(String[] args)
{
	Scanner in = new Scanner(System.in);
	int t = in.nextInt();
	while(t-->0)
	{
		int n = in.nextInt();
		int curr = in.nextInt();
		int max = curr;
		Long sum = new Long("0");
		boolean neg = curr<0;
		int i = 1;
		while(i<n)
		{
			curr = in.nextInt();
			if((neg && curr<0) || (!neg && curr>0))
			{
				max = Math.max(curr,max);
			}
			else
			{
				//System.out.print(max+" d ");
				neg = !neg;
				sum += max;
				max = curr;
			}
			i++;
		}
		sum+=max;
		System.out.println(sum);
	}
}
}