import java.util.*;

public class Main {


    public static void main (String [] args) {


        Scanner scanner = new Scanner(System.in);
        int t = scanner.nextInt();
        for(int tt=0;tt<t;tt++ ) {
            int n = scanner.nextInt();
            int [] a = new int[n];
            for(int i=0;i<n;i++) {
                a[i] = scanner.nextInt();
            }

            int ans = 0;
            int curMax = -1;
            int curMin = Integer.MIN_VALUE;
            
            for(int i=0;i<n;i++) {
                if(a[i] > 0 && curMax < a[i]) {
                    curMax = a[i];
                    if(curMin!=Integer.MIN_VALUE){
                        ans+=curMin;
                    }
                    curMin = Integer.MIN_VALUE;
                }
                else if(a[i]<0 && curMin < a[i]) {
                    curMin = a[i];
                    if(curMax!=-1){
                        ans+=curMax;
                    }
                    curMax = -1;
                } 
            }
            if(curMin!=Integer.MIN_VALUE) {
                ans+=curMin;
            }
            if(curMax!=-1){
                ans+=curMax;
            }
            System.out.println(ans);
        }
    }
}