import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner keyboard = new Scanner(System.in);
        int numTests = keyboard.nextInt();
        while (keyboard.hasNext()) {
            int sum = 0;
            int maxpair = 0;
            int length = keyboard.nextInt();
            int max = Integer.MIN_VALUE;
            for (int i = 0; i < length; i++) {
                int pair = 0;
                int num = keyboard.nextInt();
                if (num < 0 && i < length - 1) {
                    if (num > max) {
                        max = num;
                    }
                    continue;
                }
                else if (num < 0 && i == length - 1) {
                    if (num > max) {
                        max = num;
                    }
                    System.out.println(max);
                }
                else if (num < 0 && max > 0) {
                    pair += max;
                    max = num;
                }
                else if (num > 0 && max < 0) {
                    pair +=  max;
                    if (pair < 0) {
                        if (pair > maxpair) {
                            maxpair = pair;
                        }
                    } else {
                        sum += pair;
                    }
                    max = num;
                }
                if (num > max) {
                    max = num;
                }
            }
            if(sum >= 0) {
                System.out.println(sum);
            } else {
                System.out.println(maxpair);
            }
        }
    }
}