import java.io.*;
import java.util.*;

public class Main {
    static PrintWriter out;

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(new BufferedOutputStream(System.out));
        int t = Integer.parseInt(br.readLine().trim());
        while (t-- > 0){
            int n = Integer.parseInt(br.readLine().trim());
            int p[] = new int[n];
            String[] s = br.readLine().split(" ");
            for (int i = 0; i < n; i++) {
                p[i] = Integer.parseInt(s[i]);
            }
            long sum = 0;
            int max = p[0];
            boolean b = false;
            if(p[0] > 0) b = true;
            for (int i = 0; i < n ; i++) {
                if(p[i] > 0){
                    if(b){
                        max = Math.max(p[i],max);
                    }else {
                        sum += max;
                        b = true;
                        max = p[i];
                    }
                }else{
                    if(b){
                        sum += max;
                        b = false;
                        max = p[i];
                    }else{
                        max = Math.max(p[i],max);
                    }
                }
            }
            out.println(sum+max);
        }
        out.close();
    }



    static class MyUtils {
        //《---------------------------工具类---------------------------》
        //[begin, end) 进行二分查找，返回 大于或等于 tar的第一个元素位置。如果所有元素都小于tar，则返回 end.
        public static int lowerBound(int []nums,int l,int r,int target){
            while(l<r){
                int m = (l+r)/2;
                if(nums[m]>=target) r= m;
                else    l = m +1;
            }
            return l;

        }

        private static int gcd(int a, int b) {
            return a%b==0?a:(gcd(b,a%b));
        }

        // [begin, end) 进行二分查找，返回 大于 tar的第一个元素位置。如果所有元素都小于tar，则返回 end.
        public static int upperBound(int []nums ,int l,int r, int target){
            while(l<r){
                int m = (l+r)/2;
                if(nums[m]<=target) l = m+1;
                else    r = m;
            }
            return l;
        }
    }
}







