import java.util.Scanner;
public class Sequence {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int cases = sc.nextInt();
        for(int i=1; i<=cases; i++){
            int elements = sc.nextInt();
            int[] num = new int[elements];
            long sum =0L;
            for(int j=0; j<elements; j++){
                num[j] = sc.nextInt();
            }
            int temp = num[0];
            if (cases==1)
                sum +=temp;
            else {
                for (int k = 0; k < elements - 1; k++) {
                    if (sameSign(num[k], num[k + 1])) {
                        temp = findMax(temp, num[k + 1]);
                        if (k + 1 == elements - 1)
                            sum += temp;
                    } else {
                        sum += temp;
                        temp = num[k + 1];
                        if (k + 1 == elements - 1)
                            sum += temp;
                    }
                }
            }
            System.out.println(sum);
        }
    }

    public static int findMax(int a, int b){
        return (a>=b)?a:b;
    }

    public static boolean sameSign(int a, int b){
        return (a>0 && b>0) || (a<0 && b<0);
    }
}
