import java.util.HashMap;
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int t = scan.nextInt();
        while(t-->0){
            int n = scan.nextInt();
            long cp = 0, cn = 0 , op = 0, on = 0;
            boolean flag =false;
            for(int i = 0; i<n;i++){
                int v = scan.nextInt();
                if(i == 0){
                    if(v<0){
                        flag = true;
                        cn = v;
                    }
                    else{
                        flag = false;
                        cp = v;
                    }
                }
                else{
                    if(flag){
                        if(v<0){
                            if(cn < v) cn = v;
                        }
                        else{
                            op += cp;
                            cp = v;
                            flag = false;
                        }
                    }
                    else{
                        if(v>0){
                            if(cp < v) cp =v;
                        }
                        else{
                            on += cn;
                            cn = v;
                            flag = true;
                        }
                    }
                }
            }
            System.out.println(op+cp+on+cn);
        }
    }
}