import java.util.Scanner;
import java.util.Stack;

public class cf1 {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int t = scan.nextInt();
        for(int s=0; s<t; s++){
            int n = scan.nextInt();
            Stack st = new Stack<Long>();
            long prev=0;
            for (int i = 0; i < n; i++) {
                long num = scan.nextLong();
                if(i==0){
                    st.push(num);
                    prev = num;
                }
                else{
                    if(num*prev>0&&num>prev){
                        st.pop();
                        st.push(num);
                    }
                    else if(num*prev<0){
                        st.push(num);
                        prev = num;
                    }
                }
            }
            long sum=0;
            int sizes = st.size();
            for (int i = 0; i < sizes; i++) {
                sum += (long) st.pop();
            }
            System.out.println(sum);
        }
    }

}