//package cfRound636;

import java.io.FileReader;
import java.util.ArrayList;
import java.util.Scanner;

public class Problem3 {

	public static void main(String[] args) throws Exception{

		//Scanner in = new Scanner(new FileReader("C:\\Users\\Gamingrig\\kinglionleo-workspace\\USACO Problems\\src\\cfRound636\\Numbers"));
		Scanner in = new Scanner(System.in);

		int N = in.nextInt();
		for(int i=0; i<N; i++) {
			
			long size = in.nextInt();
			long sum = 0;
			
			long first = in.nextInt();
			long maximum = first;
			
			boolean isPositive = first >= 0;
			
			for(int j=1; j<size; j++) {
				
				int current = in.nextInt();
				
				if((isPositive && current >= 0) || (!isPositive && current < 0)) {
					
					if(current>maximum) maximum = current;
					
				}
				
				else {
					
					sum += maximum;
					isPositive = !isPositive;
					maximum = current;
					
				}
				
				
				
			}
			
			sum += maximum;
			
			System.out.println(sum);
			
			
		}
		
	}

}
