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

public class Solution {
    public static void main(String[] args) throws Exception {
        FastReader sc = new FastReader();
        int t=sc.nextInt();
        while (t-->0){
            int n=sc.nextInt();
            int a[]=new int[n+1];
            for (int i=1;i<=n;i++)a[i]=sc.nextInt();
            int i=0;
            long sum=0;
            while (i<=n){
                int mx=0;
                while (i<=n && a[i]>0 ){
                    mx=Math.max(a[i],mx);
                    i++;
                }
                sum+=mx;
                i++;

            }
            i=0;
            while (i<=n){
                int mx=Integer.MIN_VALUE;
                while (i<=n && a[i]<0 ){
                    mx=Math.max(a[i],mx);
                    i++;
                }
                if (mx!=Integer.MIN_VALUE) {
                    sum += mx;
                }
                i++;

            }
            System.out.println(sum);
        }

    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}
