import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class CF1343C {

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task task = new Task();
        task.solve(in, out);
        out.close();
    }

    static class Task {
        private static boolean POSITIVE = true;
        public void solve(InputReader in, PrintWriter out) {
            int t = in.nextInt();
            for (int k = 0; k < t; ++k) {
                int n = in.nextInt();
                long max = in.nextLong();
                int i = 1;
                long ans = 0;
                boolean flag = max > 0;
                while (i < n) {
                    while (i < n) {
                        long b = in.nextLong();
                        ++i;
                        if (flag != (b > 0)) {
                            flag = b > 0;
                            ans += max;
                            max = b;
                            break;
                        } else {
                            if (b > max) { max = b; }
                        }
                    }
                }
                out.println(ans + max);
            }
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() { return Integer.parseInt(next()); }
        public long nextLong() { return Long.parseLong(next()); }
    }
}
