t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int,input().split()))
    pos = a[0]>0
    current = a[0]
    reduced = []
    for x in a:
        if pos and x>0:
            current = max(x,current)
        elif pos:
            reduced.append(current)
            current = x
            pos = False
        elif not pos and x < 0:
            current = max(x,current)
        else:
            reduced.append(current)
            current = x
            pos = True
    reduced.append(current)
    print (sum(reduced))
