import java.io.PrintWriter;
import java.util.*;
import java.util.Scanner;

public class AltSubsequence {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int t = sc.nextInt();
        for (int i1 = 0; i1 < t; i1 ++){
            int n = sc.nextInt();
            int[] sequence = new int[n];
            for (int i2 = 0; i2 < n; i2 ++){
                sequence[i2] = sc.nextInt();
            }
            long sum = 0;
            int last = sequence[0];
            for (int i3 = 1; i3 < n; i3 ++){
                if (sequence[i3] * sequence[i3 - 1] > 0){
                    last = Math.max(sequence[i3], last);
                }
                if (sequence[i3] * sequence[i3 - 1] < 0){
                    sum += last;
                    last = sequence[i3];
                }
                if (i3 == sequence.length - 1){
                    sum += last;
                }
            }
            pw.println(sum);
        }
        pw.close();
    }
}
