import java.util.Scanner;

public class Solution {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int t = scan.nextInt();
        while(t-- > 0){
            int n = scan.nextInt();
            int num = scan.nextInt();
            long sum = 0;
            sum += num;
            int mx = num;
            for(int i = 1; i < n; i++){
                num = scan.nextInt();
                if(mx > 0 && num < 0){
                    sum += num;
                    mx = num;
                } else if(mx < 0 && num > 0) {
                    sum += num;
                    mx = num;
                } else {
                    sum -= mx;
                    mx = Math.max(mx, num);
                    sum += mx;
                }
            }
            System.out.println(sum);
        }
        scan.close();
    }
}