import java.util.*;

public class Alternate {
    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();
            }
            int i = 0;
            long max = 0;
            while(i<n) {
                int cur = arr[i];
                int j = i;
                while(j<n && sign(arr[i])==sign(arr[j])) {
                    cur = Math.max(cur, arr[j]);
                    j++;
                }
                max += cur;
                i = j;
            }
            System.out.println(max);
        }
    }

    public static int sign(int n) {
        if(n<0) {
            return -1;
        }
        return 1;
    }

    
}
