//Code by Sounak, IIEST
import java.io.*;
import java.math.*;
import java.util.*;
import java.util.Arrays;

public class Test2{
    public static void main(String args[])throws IOException{
        FastReader sc = new FastReader();
        StringBuilder sb = new StringBuilder();
        int test=sc.nextInt();
        while(--test>=0)
        {
            int n=sc.nextInt();
            long a[]=new long[n];
            int i;
            for(i=0;i<n;i++)
            a[i]=sc.nextLong();
            long curr=a[0],count=0;
            for(i=1;i<n;i++)
            {
                if((a[i]>0 && a[i-1]<0) || (a[i]<0 && a[i-1]>0))
                {
                    count+=curr;
                    //System.out.println(curr);
                    curr=a[i];
                }
                curr=Math.max(curr,a[i]);
                
            }
            count+=curr;
            System.out.println(count);
        }
    }
}


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;
    }
}