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

public class SubSequence {
    public static void main(String[] args) throws Exception {
        new SubSequence().read();
    }

    public void read() throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int T = Integer.valueOf(br.readLine());

        for (int t = 1; t <= T; t++) {
            this.testCase(t, br);
        }
        br.close();
    }

    public void testCase(int testNumber, BufferedReader br) throws Exception{
        int n=Integer.valueOf(br.readLine());
        String temp[]=br.readLine().split(" ");
        int arr[]=new int[n];
        for(int i=0;i<n;i++)
            arr[i]=Integer.valueOf(temp[i]);
        int maxNegative=Integer.MIN_VALUE;
        int maxPositive=Integer.MIN_VALUE;
        ArrayList<Integer> list=new ArrayList<>();
        list.add(arr[0]);
        for(int i=1;i<arr.length;i++){
            if(arr[i]>=0 && arr[i-1]<0){
                list.add(arr[i]);
            }else if(arr[i]<0 && arr[i-1]>=0){
                list.add(arr[i]);
            }else {
                list.set(list.size() - 1, Math.max(list.get(list.size() - 1), arr[i]));
            }
        }
        //StringBuilder sb=new StringBuilder();
        //sb.append(list.get(0));
        long sum=list.get(0);
        for(int i=1;i<list.size();i++){
            sum+=list.get(i);
            //sb.append(" "+list.get(i));
        }
        //System.out.println(list);
        System.out.println(sum);
    }


}
