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


public class JavaApplication3 {
    public static void main(String[] args) {
Scanner sc  = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
int t = sc.nextInt();
for (int i = 0; i < t; i++) {
   int n = sc.nextInt();
   int arr[] = new int [n];
    for (int j = 0; j < n; j++) {
        arr[j] = sc.nextInt();
    }
    int max  = arr[0];
    int sum = 0 ;
    for (int j = 1; j < n; j++) {
        if (arr[j] *  arr[j-1] < 0) {
          sum+=max;
          max = arr[j];
        }else 
        {
        max = Math.max(max,arr[j]);
        }
    }
 
    
        System.out.println(sum+max);
    

  
}





    
}}