import java.util.*;
public class SubSeqSumBySize {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t-- > 0){
            int n = sc.nextInt();
            int[] a = new int[n];
            for(int i=0;i<n;i++){
                a[i] = sc.nextInt();
            }
            System.out.println(maxSumBySize(a,n));
        }
        sc.close();
    }

    private static long maxSumBySize(int[] a, int n) {
        long sum = 0;int max;
        int i = 0;
        while(i < n){
            max = Integer.MIN_VALUE;
            int x = (a[i] > 0) ? -1 : 1;
            while(i < n && a[i] * x < 0){
                max = Math.max(max, a[i]);
                i++;
            }
            sum += max;
        }
        return sum;
    }
}