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

public class Solution {

    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        while(t--!=0)
        {
            int n=sc.nextInt();
            int p=sc.nextInt();
            long max=Integer.MIN_VALUE;
            long s=p;
            for(int i=1;i<n;i++){
                int a=sc.nextInt();
                if((p*a)>0){
                    if(a>p){
                        s-=p;
                        s+=a;
                        p=a;
                    }
                }
                else{
                    s+=a;
                    p=a;
                }
            }
            System.out.println(s);
        } 
    }
}


    