import java.util.Scanner;

public class AlternatingSubsequence {
    public static void main(String[] args) {
        Scanner sc  = new Scanner(System.in);
        int t = sc.nextInt();
        while(t > 0){
            int n = sc.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = sc.nextInt();
            }
            solve(n,arr);
            t--;
        }
        sc.close();
    }

    private static void solve(int n, int[] arr) {
        int []result = new int[n];
        result[0] = arr[0];
        long sum = 0;
        for(int i=1;i<n;i++){
            if((result[i-1] >0 && arr[i] < 0) ||(result[i-1] <0 && arr[i] > 0)){
                sum += result[i-1];
                result[i] = arr[i];
                continue;
            }
            result[i] = Math.max(result[i-1], arr[i]);
        }
        sum += result[result.length-1];
        System.out.println(sum);

    }
}
