import java.util.*;

public class Solution {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        for (int i = 0; i < t; i++) {
            int n = sc.nextInt();
            int[] ar = new int[n];
            ar[0] = sc.nextInt();
            int idx = 0;
            for (int j = 1; j < n; j++) {
                int tmp = sc.nextInt();
                if (ar[idx]<0 && tmp<0){
                    ar[idx] = Math.max(ar[idx], tmp);
                }
                else if (ar[idx]>0 && tmp>0) {
                    ar[idx] = Math.max(ar[idx], tmp);
                }
                else {
                    idx++;
                    ar[idx] = tmp;
                }
            }
            long ans = 0;
            for (int j = 0; j <= idx; j++) {
                ans += ar[j];
            }
            System.out.println(ans);
        }
    }
}