
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;
import java.util.StringTokenizer;

public class Main {

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

    public static void main(String args[]) {
        FastReader In = new FastReader();
        int t = In.nextInt();
        for(int i=0; i < t;i++){
            int n = In.nextInt();
            int[] arr = new int[n];
            for(int j = 0; j < n;j++){
                arr[j] = In.nextInt();
            }
            long total = 0;
            int maxl = Integer.MIN_VALUE;
            for(int j = 0; j < n-1;j++){
                boolean act = arr[j] > 0;
                boolean next = arr[j+1] > 0;
                maxl = Math.max(maxl,arr[j]);
                if(act != next){
                    total += maxl;
                    maxl = Integer.MIN_VALUE;
                }
            }
            if(n == 1){
                System.out.println(arr[0]);
            }else{
                maxl = Math.max(maxl,arr[n-1]);
                total += maxl;
            }
            System.out.println(total);
        }
    }
}




