for _ in range(int(input())):
    n = int(input())
    arr = [int(i) for i in input().split()]
    flag = arr[0] > 0
    result = 0
    temp = arr[0]
    for elem in arr:
        if flag == elem > 0:
            temp = max(temp, elem)
        elif flag and elem < 0:
            result += temp
            temp = elem
            flag = False
        elif not flag and elem > 0:
            result += temp
            temp = elem
            flag = True
        else:
            temp = max(temp, elem)
    print(result + temp)