import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        
        int T = in.nextInt();
        int n;
        int num[] = new int[200005];
        while(T > 0) {
            T--;
            n = in.nextInt();
            for(int i = 0; i < n; ++i) num[i] = in.nextInt();

            boolean check;
            if(num[0] < 0) check = false;
            else check = true;
            long sum = 0;
            int var = -0x3f3f3f3f;

            for(int i = 0; i < n; ++i) {
                if(check != (num[i] > 0)) {
                    check = !check;
                    sum += var;
                    var = num[i];
                }
                else {
                    var = Math.max(var, num[i]);
                }
            }
            sum += var;
            System.out.println(sum);
        }

        in.close();
    }
}