import java.util.*;
public class sol{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int tc=sc.nextInt();
        for(int i=0;i<tc;i++){
        int n=sc.nextInt();
        int arr[]=new int[n];
        for(int j=0;j<n;j++)
          arr[j]=sc.nextInt();
          int ind=1;
          long sum=0;
          while(ind<n){
              if(arr[ind]*arr[ind-1]<0)
              sum+=arr[ind-1];
              if(arr[ind]*arr[ind-1]>0){
                  if(arr[ind-1]>arr[ind])
                   arr[ind]=arr[ind-1];
              }
              ind++;
          }
          sum+=arr[n-1];
          System.out.println(sum);
        }
    }
}