import java.util.*;

public class C {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        
        while(t-- > 0) {
            int n = in.nextInt();
            int ans = 0, max = 0;
            boolean sign = true;
            int arr[] = new int[n];
                
            for(int i = 0; i < n; i++) {
                int num = in.nextInt();
                if(num < 0) {
                    if(sign) {
                       ans += max;
                       max = num;
                    } else {
                         max = Math.max(max, num);
                    }
                    sign = false;
                } else {
                    if(sign)
                        max = Math.max(max, num);
                    else {
                         ans += max;
                         max = num;
                        }
                        sign = true;
                }
            }
            ans += max;
            System.out.println(ans);
        }
    }
}