
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class Solution {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
		String inp[];
		int t = Integer.parseInt((br.readLine()));
		while (t-- > 0) {
			int N = Integer.parseInt(br.readLine().trim());
			inp = br.readLine().split(" ");
			int arr[] = new int[N];
			for (int i = 0; i < N; i++) {
				arr[i] = Integer.parseInt(inp[i]);
			}
			int i = 0;
			int max = 0;
			long ans = 0;
			while (i < N) {
				if (arr[i] < 0) {
					max = arr[i];
					while (i < N && arr[i] < 0) {
						max = Math.max(max, arr[i]);
						i++;
					}
					ans += max;
				} else {
					max = arr[i];
					while (i < N && arr[i] > 0) {
						max = Math.max(max, arr[i]);
						i++;
					}
					ans += max;
				}
			}
			bw.write(String.valueOf(ans) + "\n");
			bw.flush();
		}
	}
}
