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

public class Main {
    public static void main(String[] args) throws IOException {
        int test = nextInt();
        for (int iiiiiii = 0; iiiiiii < test; iiiiiii++) {
            int n = nextInt();
            int[] a = new int[n];
            long[] sum = new long[n];
            long max = Long.MIN_VALUE;
            int[] dp = new int[n];
            int ml = 0;
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            for (int i = 0; i < n; i++) {
                int ma = 0;
                int idx = -1;
                long summ = Long.MIN_VALUE;
                if (a[i] > 0) {
                    for (int j = 0; j < i; j++) {
                        if (a[j] < 0 && dp[j] >= ma&&summ<sum[j]) {
                            ma = dp[j];
                            idx = j;
                            summ=sum[j];
                        }
                    }
                } else {
                    for (int j = 0; j < i; j++) {
                        if (a[j] > 0 && dp[j] >= ma&&summ<sum[j]) {
                            ma = dp[j];
                            idx = j;
                            summ=sum[j];
                        }
                    }
                }
                dp[i] = ma + 1;
                sum[i] = a[i];
                if (idx > -1) sum[i] += sum[idx];
                if (ml == dp[i]) {
                    max = Math.max(sum[i], max);
                }
                else if(ml<dp[i]){
                    ml=dp[i];
                    max = sum[i];
                }
            }
            out.println(max);
        }
        out.close();
    }


    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter out = new PrintWriter(System.out);
    static StringTokenizer in = new StringTokenizer("");


    public static boolean hasNext() throws IOException {
        if (in.hasMoreTokens()) return true;
        String s;
        while ((s = br.readLine()) != null) {
            in = new StringTokenizer(s);
            if (in.hasMoreTokens()) return true;
        }
        return false;
    }

    public static String nextToken() throws IOException {
        while (!in.hasMoreTokens()) {
            in = new StringTokenizer(br.readLine());
        }
        return in.nextToken();
    }

    public static int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    public static double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    public static long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
}