import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class AlternatingSubsequence {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int T = sc.nextInt();
        for (int i = 0; i < T; i++) {
            int N = sc.nextInt();
            List<Integer> list = new ArrayList<>();
            for (int j = 0; j < N; j++) {
                int a = sc.nextInt();
                list.add(a);
            }
            List<Integer> best = new ArrayList<>();
            int max = list.get(0);

            for (int j = 1; j < N; j++) {
                if ((list.get(j) > 0 && max > 0) || (list.get(j) < 0 && max < 0)) {
                    max = Math.max(list.get(j), max);
                } else {
                    best.add(max);
                    max = list.get(j);
                }

            }
            best.add(max);
            // System.out.println(best);
            long sum = 0;
            for (int j = 0; j < best.size(); j++) {
                sum += best.get(j);
            }
            out.println(sum);
        }
        out.close();

    }

}
