import java.util.Scanner;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Abc {
	public static void main(String[] args) {
		Scanner kb = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int t = kb.nextInt();
		while (t-- > 0) {
			int n = kb.nextInt();
			int arr[] = new int[n];
			for (int i = 0; i < n; i++) {
				arr[i] = kb.nextInt();
			}
			int curr = arr[0];
			int sum = 0;
			int max = 0;
			for (int i = 0; i < n - 1; i++) {
				if (arr[i] < 0 && arr[i + 1] > 0) {
					sum += arr[i] + arr[i + 1];
				} else if (arr[i] > 0 && arr[i + 1] < 0) {
					sum += arr[i] + arr[i + 1];
				}
			}
			System.out.println(sum);
		}
	}

}