for _ in range(int(input())):
    n = int(input())
    data = list(map(int, input().split()))
    result = 0

    if data[0] > 0:
        sign = 1
    else:
        sign = -1
  
    array = []
 
    for x in data:
        if sign == 1 and x > 0:
            array.append(x)
        if sign == 1 and x < 0:
            sign = -1
            result += max(array)
            array = [x]
        if sign == -1 and x < 0:
            array.append(x)
        if sign == -1 and x > 0:
            sign = 1
            result += max(array)
            array = [x]
  
    result += max(array)
    print(result)