t = int(input())

for test in range(t):
    n = int(input())
    a = [int(x) for x in input().split()]
    segments = []
    if a[0] > 0:
        positive = True
    else:
        positive = False
    
    current = []
    for e in a:
        if e > 0 and positive:
            current.append(e)
        elif e < 0 and not positive:
            current.append(e)
        elif e > 0 and not positive:
            segments.append(current)
            current = [e]
            positive = True
        else:
            segments.append(current)
            current = [e]
            positive = False
    
    segments.append(current)
    total = 0
    for segment in segments:
        total = total + max(segment)
    print(total)