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

public class CF1343C {
    public static void main(String[] args) {
        FastReader input = new FastReader();
        int t = input.nextInt();
        while (t > 0){
            int n = input.nextInt();
            int[] arr = new int[n];
            for(int i = 0;i < n;i++){
                arr[i] = input.nextInt();
            }
            int i = 0;
            int maxPos = Integer.MIN_VALUE;
            int minPos = Integer.MIN_VALUE;
            ArrayList<Integer> list = new ArrayList<Integer>();
            while (i < n){
                if(arr[i] > 0){
                    while (i < n && arr[i] > 0){
                        maxPos = Math.max(maxPos,arr[i]);
                        i++;
                    }
                    list.add(maxPos);
                    maxPos = Integer.MIN_VALUE;
                }
                else{
                    while (i < n && arr[i] < 0){
                        minPos = Math.max(minPos,arr[i]);
                        i++;
                    }
                    list.add(minPos);
                    minPos = Integer.MIN_VALUE;
                }
            }
            long sum = 0;
            for(int l : list){
                sum += l;
            }
            System.out.println(sum);
            t--;
        }
    }
    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;
        }
    }
}
