
import java.util.*;
import javafx.util.*;

public class Expert {

    public static Scanner in = new Scanner(System.in);

    public static long solve(long[] z) {
        long sum = 0;

        for (int i = 1; i < z.length; i++) {
            long cur = z[i];
            long pre = z[i - 1];
            if (cur < 0 && pre < 0) {
                z[i] = Math.max(cur, pre);
                z[i - 1] = 0;
            } else if (cur > 0 && pre > 0) {
                z[i] = Math.max(cur, pre);
                z[i - 1] = 0;
            }
        }

        ArrayList<Long> pos = new ArrayList<Long>();
        ArrayList<Long> neg = new ArrayList<Long>();
        for (long val : z) {
            if (val != 0) {
                if (val > 0) {
                    pos.add(val);
                } else {
                    neg.add(val);
                }
            }

        }
        int sz = Math.min(pos.size(), neg.size());
        Collections.sort(pos, Collections.reverseOrder());
        Collections.sort(neg, Collections.reverseOrder());
        int tmp = sz;
        for (int i = 0; i < pos.size(); i++) {
            if (sz > 0) {
                sum += pos.get(i);
                sz--;
            } else {
                break;
            }
        }
        for (int i = 0; i < neg.size(); i++) {
            if (tmp > 0) {
                sum += neg.get(i);
                tmp--;
            } else {
                break;
            }
        }
        return sum;
    }

    public static void main(String[] args) {
        int T = in.nextInt();
        while (T-- > 0) {

            int n = in.nextInt();
            long[] z = new long[n];
            boolean neg = false;
            boolean pos = false;
            for (int i = 0; i < z.length; i++) {
                z[i] = in.nextInt();
                if (z[i] < 0) {
                    neg = true;
                } else {
                    pos = true;
                }
            }
            if (neg && pos) {
                System.out.println(solve(z));
            } else {
                if (pos) {
                    long max = -1;
                    for (long val : z) {
                        max = Math.max(max, val);
                    }
                    System.out.println(max);
                } else {
                    long max = Long.MIN_VALUE;
                    for (long val : z) {
                        max = Math.max(max, val);
                    }
                    System.out.println(max);
                }
            }
        }
    }

}
