import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.math.BigInteger;
import java.util.Scanner;
public class mj {
    int a[] = new int[200000], n;

    public static void main(String[] args) {
        int n, t, i, length, m, sign = 1;
        int[] a = new int[200000];
        BigInteger sum = new BigInteger("0");
        Scanner sc = new Scanner(System.in);
        t = sc.nextInt();
        while(t>0){
            length = 0;
            sum = BigInteger.valueOf(0);
            m = -1000000001;
            n = sc.nextInt();
            for (i = 0; i < n; i++){
                a[i] = sc.nextInt();
                if (((a[i] > 0) && (sign > 0)) || ((a[i] < 0) && (sign < 0))){
                    if (a[i] > m) m = a[i];

                }
                else{
                    length++;
                    sign = -sign;
                    sum = sum.add(BigInteger.valueOf(m));
                    m = a[i];
                    // System.out.println("This is " +i);
                }

            }
            sum = sum.add(BigInteger.valueOf(m));
            System.out.println(sum);
            t--;
        }
        // arr = new int[n];
        // while ( i<n) {
        //     arr[i] = sc.nextInt();
        //     i++;
        // }
        // File file1 = new File("output.txt");
        // PrintStream stream = new PrintStream(file1);
        // System.setOut(stream);
        // for(i =0; i<n; i++ ) {
        //     if (arr[i] % 2 == 0)
        //         System.out.println("1");
        //     else
        //         System.out.println("0");
        // }
    }
}