import java.util.*;
import java.io.*;

public class problemC {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        // Scanner in = new Scanner(new File("input.in"));
        // PrintWriter out = new PrintWriter(new File("output.out"));

        int t = in.nextInt();
        for (int i = 0; i < t; i++) {
            int n = in.nextInt();
            long[] sequence = new long[n];
            for (int j = 0; j < n; j++) {
                sequence[j] = in.nextLong();
            }

            long[] subMaxes = new long[n];
            int subMaxCounter = 0;
            subMaxes[0] = sequence[0]; 

            for (int j = 0; j < n - 1; j++) {
                if (sequence[j + 1] >= 0 && sequence[j] >= 0 && sequence[j + 1] > sequence[j]) {
                    subMaxes[subMaxCounter] = sequence[j + 1];
                } else if (sequence[j + 1] < 0 && sequence[j] < 0 && sequence[j + 1] > sequence[j]) {
                    subMaxes[subMaxCounter] = sequence[j + 1];
                } else if (sequence[j + 1] < 0 && sequence[j] >= 0) {
                    subMaxCounter = subMaxCounter + 1;
                    subMaxes[subMaxCounter] = sequence[j + 1];
                } else if (sequence[j + 1] >= 0 && sequence[j] < 0) {
                    subMaxCounter = subMaxCounter + 1;
                    subMaxes[subMaxCounter] = sequence[j + 1];
                }
            }

            long maxSum = 0;

            for (int j = 0; j <= subMaxCounter; j++) {
                maxSum = maxSum + subMaxes[j];
            }
            if (subMaxCounter == 0) {
                System.out.println(0);
            } else {
                System.out.println(maxSum);
            }
            
        }
        in.close(); 
        // out.close();
    } 
}