import java.util.*;

public class AlternatingSubsequence 
{
    public static void main(String [] args)
    {
        Scanner input = new Scanner(System.in);
        int t = input.nextInt();

        for(int i = 0; i < t; i++)
        {
            int n = input.nextInt();

            List<Integer> list = new ArrayList<>();
            for(int j = 0; j < n; j++) list.add(input.nextInt());
            
            long negativeCounter = list.stream().filter(j -> j < 0).count();
            if(negativeCounter == list.size())
            {
                int maxNegative = list.stream()
                                      .mapToInt(Integer::intValue)
                                      .max()
                                      .getAsInt();

                System.out.println(maxNegative);                      
            }
            else
            {
                int maxPositive = list.stream()
                                      .mapToInt(Integer::intValue)
                                      .max()
                                      .getAsInt();

                int maxNegative = list.stream()
                                      .filter(j -> j < 0)
                                      .mapToInt(Integer::intValue)
                                      .max()
                                      .getAsInt();
                long sum1 = maxPositive + maxNegative;
                System.out.println(sum1);
            }
        }
        input.close();
    }
}