/**
 * Author: Rohan Arora(codiinggeek)
 */

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

public class RT {
    static long mod = (long) Math.pow(10, 9) + 7;

    public static void main(String[] args) {
        try {
            FastReader s = new FastReader();
            int t = s.nextInt();
            while(t-->0){
                int n = s.nextInt();
                long ar[] = new long[n+1];
                for(int i=0;i<n;i++){
                    ar[i] = s.nextLong();
                }
                ar[n]=0;
                long p = ar[0];
                long sum=0;
                long max=ar[0];
                int y=0;
                if(p>0){
                    y=1;
                }else {
                    y=-1;
                }

                for(int i=1;i<=n;i++){
                    if(i==n){
                        sum += max;
                        break;
                    }
                        if((ar[i]>0&&y==1)||(ar[i]<0&&y==-1)){
                            max = Math.max(max, ar[i]);
                        }else if(ar[i]>0&&y==-1){
                            y=1;
                            sum += max;
                            max = ar[i];
                        }else if(ar[i]<0&&y==1) {
                            y = -1;
                            sum += max;
                            max = ar[i];
                        }
                }

                System.out.println(sum);
            }
        } catch (Exception e) {
            System.out.println(e);
            return;
        }
    }

    /**Pair class */
    class Pair<U, V> {
        U first;
        V second;

        Pair(U a, V b) {
            first = a;
            second = b;
        }
    }
/**---------------------------------------------------------------------------------*/
    /** FAST I/O */
    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;
        }
    }
} 
