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

public class C {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int t = Integer.parseInt(in.readLine());
		for (int i = 0; i < t; i++) {
			int n = Integer.parseInt(in.readLine());
			StringTokenizer token = new StringTokenizer(in.readLine());
			int[] A = new int[n];
			for(int a = 0; a < n; a++)
				A[a] = Integer.parseInt(token.nextToken());
			int idx = 0;
			long sum = 0;
			while(idx < n) {
				int max = Integer.MIN_VALUE;
				if(A[idx] < 0) {
					while(idx < n && A[idx] < 0)
						max = Math.max(A[idx++], max);
				}
				else{
					while(idx < n && A[idx] > 0)
						max = Math.max(A[idx++], max);
				}
				sum += max;
			}
			System.out.println(sum);
		}
	}
}