/* package whatever; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
public class Ideone
{
	public static void main(String[] args) throws java.lang.Exception{
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
		int t = Integer.parseInt(input.readLine());
		for(int i=0;i<t;i++) {
			int n = Integer.parseInt(input.readLine());
			String[] nums = input.readLine().split(" ");
			int a = 0;
			int b = 0;
			long sum = 0;
			long max = Integer.parseInt(nums[a]);
			while(b<nums.length) {
				//System.out.println(a+" "+b+" "+max);
				if(Integer.parseInt(nums[a])*Integer.parseInt(nums[b])>0) {
					max = Math.max(max, Integer.parseInt(nums[b]));
				}else {
					sum = sum+max;
					a = b;
					max = Integer.parseInt(nums[a]);
					//System.out.println(sum+" "+max);
				}
				b++;
			}
			System.out.println(sum+max);
		}
	}
}