import java.util.*;

public class Solution {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int T = scan.nextInt();
        for(int t = 0; t < T; t++) {
            int N = scan.nextInt();
            boolean isNeg = false;
            long sum = 0, val = 0;
            for(int i = 0; i < N; i++) {
                int v = scan.nextInt();
                if((v < 0) != isNeg) {sum += val; isNeg = v < 0; val = v;}
                val = Math.max(val, v);
            }
            sum += val;
            System.out.println(sum);
        }
    }
}
