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

public class Main {
    BufferedReader in;
    PrintWriter out;
    StringTokenizer st = new StringTokenizer("");

    public static void main(String[] args) throws Exception {
        (new Main()).run();
    }

    void run() throws Exception {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);

        int T = nextInt();
        int N = 1 << 19;

        for (int t = 0; t < T; t++) {
            int n = nextInt();
            int posLen = 0;
            int negLen = 0;
            long posSum = 0;
            long negSum = 0;
            for (int i = 0; i < n; i++) {
                int cur = nextInt();
                if (cur > 0) {
                    if (posLen <= negLen + 1) {
                        if ((posLen < negLen + 1) || (posSum < negSum + cur)) {
                            posLen = negLen + 1;
                            posSum = negSum + cur;
                        }
                    }
                } else {
                    if (negLen <= posLen + 1) {
                        if ((negLen < posLen + 1) || (negSum < posSum + cur)) {
                            negLen = posLen + 1;
                            negSum = posSum + cur;
                        }
                    }
                }
            }
            long ans = posSum;
            if ((negLen > posLen) || (negLen == posLen && ans < negSum)) {
                ans = negSum;
            }
            out.println(ans);
        }

        in.close();
        out.close();
    }

    String nextToken() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }
}
