import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String args[]) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int test = Integer.parseInt(br.readLine());
        while(test-->0){
            int n = Integer.parseInt(br.readLine());
            String[] tokens = br.readLine().split(" ");
            long sum=0;
            int num = Integer.parseInt(tokens[0]);
            int max = num;
            boolean positive = num>0 ? true : false;
            for(int i=1;i<n;i++){
                num = Integer.parseInt(tokens[i]);
                if((positive && num>0) || (!positive && num<0)){
                    max = Math.max(num,max);
                }else if((positive && num<0) || (!positive && num>0)){
                    sum+=max;
                    positive = !positive;
                    max = num;
                }
            }
            sum+=max;
            System.out.println(sum);
        }

    }


}
