import java.util.*;

public class AlternatingSubsequence 
{
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		int t = scan.nextInt();
		
		for (int i = 0; i < t; i++)
		{
			long[] a = new long[scan.nextInt()];
			for (int j = 0; j < a.length; j++)
				a[j] = scan.nextLong();
				
			int maxLength = 0;
			long maxSum = 0;
			for (int j = 0; j < a.length; j++)
			{
				long thisNum = a[j];
				long thisSum = a[j];
				int thisLength = 1;
				
				for (int k = j+1; k < a.length; k++)
				{
					if (a[k]*thisNum < 0)
					{
						thisNum = a[k];
						thisSum += a[k];
						thisLength++;
					}
				}
				
				if (j == 0)
				{
					maxLength = thisLength;
					maxSum = thisSum;
				}
				else
					if ((thisLength >= maxLength) && (thisSum > maxSum))
					{
						maxLength = thisLength;
						maxSum = thisSum;
					}
			}
			
			System.out.println(maxSum+"");
		}
	}
}
