t = int(input())

for _ in range(t):
    n = int(input())
    a = tuple(map(int, input().split()))
    sgn = lambda x: x > 0
    flag = sgn(a[0])
    total, zone = 0, a[0]
    for elem in a:
        if sgn(elem) == flag:
            zone = max(zone, elem)
        else:
            flag = not flag
            total += zone
            zone = elem

    print(total + zone)