import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

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

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		
		StringTokenizer line = new StringTokenizer(in.readLine());
		
        long t = Long.parseLong(line.nextToken());
        
        while (t-- > 0) {
        	
        	line = new StringTokenizer(in.readLine());
        	
            int n = Integer.parseInt(line.nextToken());
            
            long[] a = new long[n];
            
            line = new StringTokenizer(in.readLine());
            
            for (int i = 0; i < n; i++) {
                a[i] = Integer.parseInt(line.nextToken());
            }
            
            long sum = 0;
            long max = a[0];
            
            for (int i = 0; i < n; i++) {
                if (max * a[i] < 0) {
                    sum += max;
                    max = a[i];
                } else {
                    if (max < a[i]) {
                    	max = a[i];
                    }
                }
            }
            
            sum += max;
            System.out.println(sum);
        }
		
	}
}
