import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.StringTokenizer;


public class Main {

    public static void main(String[] args) throws IOException {

        int T = gi();
        for (int t = 0; t < T; t++) {
            int N = gi();

            long sol = 0;
            int A[] = new int[N];
            for (int i = 0; i < N; i++) {
                A[i] = gi();
            }

            int i = 0;
            long mm ;
            while (i < N) {
                int j = i + 1;
                mm = Math.max(A[i], Long.MIN_VALUE);
                while (j < N) {
                    if ((A[i] > 0 && A[j] > 0) || (A[i] < 0 && A[j] < 0)) {
                        mm = Math.max(mm, A[j]);
                        j++;
                    } else {
                        break;
                    }
                }
                sol += mm;
                i = j;
            }
            System.out.println(sol);
        }

    }

    public static BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in), 32768);

    public static StringTokenizer stringTokenizer = null;

    public static int gi() throws IOException {
        return Integer.parseInt(next());
    }

    public static long gl() throws IOException {
        return Long.parseLong(next());
    }

    public static double gd() throws IOException {
        return Double.parseDouble(next());
    }

    public static String gs() throws IOException {
        return next();
    }

    public static char gc() throws IOException {
        return next().charAt(0);
    }

    public static String next() {
        while (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {
            try {
                stringTokenizer = new StringTokenizer(bufferedReader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return stringTokenizer.nextToken();
    }

    public static StringBuilder ap(String str) {
        answerStringBuilder.append(str);
        return answerStringBuilder;
    }

    public static StringBuilder answerStringBuilder = new StringBuilder();
}