import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;

public class Test36
{
	static boolean isAlternating(Long a, Long b)
	{
		return (a^b)<0;
	}
	public static void main(String[] args) throws IOException
	{
		BufferedReader f=new BufferedReader(new InputStreamReader(System.in));
		
		int t=Integer.parseInt(f.readLine());
		while(t-->0)
		{
			int len=Integer.parseInt(f.readLine());
			String[] s=f.readLine().split(" ");
			long[] input=new long[s.length];
			long a=0, b=0;
			ArrayList<Long> result=new ArrayList<>();
			long next=0, alt=1;
			for(int i=0; i<s.length; i++)
			{
				b=Long.parseLong(s[i]);
				if(i==0)
				{
					next=b;
					a=b;
					continue;
				}
				if(isAlternating(a, b))
				{
					result.add(next);
					next=b;
					alt++;
				}
				else
				{
					if(next<b)
					{
						next=b;
					}
				}
				a=b;
			}
			result.add(next);
			long sum=0;
			for(long integer: result)
				sum+=integer;
			System.out.println(sum);
		}
	}
}
