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

public class C{

	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int t = Integer.parseInt(br.readLine());

		for(int numCases = 1; numCases <= t; numCases++){
			int n = Integer.parseInt(br.readLine());
			StringTokenizer st = new StringTokenizer(br.readLine());
			long sum = 0;
			int first = Integer.parseInt(st.nextToken());
			boolean plus = first > 0;

			for(int i = 0; i < n - 1; i++){
				int cur = Integer.parseInt(st.nextToken());
				boolean sign = cur > 0;
				if(sign != plus){
					sum += first;
					first = cur;
					plus = sign;
				}
				else{
					first = Math.max(first, cur);
				}
			}
			sum += first;
			System.out.println(sum);
		}
		
		br.close();
	}

}