for _ in range(int(input())):
    n = int(input())
    l = list(map(int, input().split()))
    
    x = l[0] // abs(l[0])
    s = 0
    maxi = l[0]
    for i in l:
        if i // abs(i) == x:
            maxi = max(maxi, i)
        else:
            s += maxi
            x = i // abs(i)
            maxi = i
    s += maxi
    print(s)