import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Mehvix
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        P_1343C solver = new P_1343C();
        solver.solve(1, in, out);
        out.close();
    }

    static class P_1343C {
        public void solve(int testNumber, Scanner fin, PrintWriter fout) {
            int t = fin.nextInt();
            while (t-- > 0) {
                int n = fin.nextInt();
                long ans = 0;
                long cur = fin.nextLong();
                for (int i = 0; i < n - 1; i++) {
                    long x = fin.nextLong();
                    if (x < 0 ^ cur < 0) {  // ^ means one or the other, but not both or neither
                        ans += cur;
                        cur = x;
                    } else {
                        cur = Math.max(x, cur);
                    }
                }
                ans += cur;
                fout.println(ans);
            }
        }

    }
}

