for _ in range(int(input())):
    n = int(input())

    arr = list(map(int, input().split()))

    prevPos = False
    s = 0
    max_ = arr[0]
    if max_ > 0:
        prevPos = True
    
    for j in range(1, n):
        i = arr[j]
        if i > 0 :
            if prevPos:
                max_ = max(max_, i)
            else:
                prevPos = True
                s = s + max_
                max_ = i
        else:
            if not prevPos:
                max_ = max(max_, i)
            else:
                prevPos = False
                s = s + max_
                max_ = i

    print(s + max_)
