
import java.util.Scanner;

public class A {
    public static void main(String[] args) {
        int N;
        Scanner in = new Scanner(System.in);
        N = in.nextInt();
        for (int i = 0; i < N; i++) {
            int tmp = in.nextInt();
            int k;

            int maxi = 0;
            k = in.nextInt();
            int j = 1;
            long sumP = 0;
            int old = 0;
            while (j < tmp) {
                if (k > 0) {
                    maxi = k;
                    while (k > 0 && j < tmp) {
                        k = in.nextInt();
                        if (k > 0)
                        maxi = Math.max(k, maxi);
                        j++;
                    }
                    //System.out.print(maxi + " ");
                    sumP = maxi + sumP;
                    old = 1;
                }
                else {
                    maxi = k;
                    while (k < 0 && j < tmp) {
                        k = in.nextInt();
                        if (k < 0)
                        maxi = Math.max(k, maxi);
                        j++;
                    }
                    //System.out.print(maxi + " ");
                    sumP = maxi + sumP;
                    old = -1;
                }
            }
            if (k > 0 && old == -1)
                sumP= sumP + k;
            if (k < 0 && old == 1)
                sumP= sumP + k;
            System.out.println(sumP);
        }
    }
}
