t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    su = 0
    z = a[0]
    if a[0] > 0:
        tr = True
    else:
        tr = False
    for i in range(n):
        if tr == (a[i] > 0):
            z = max(z, a[i])
        else:
            su += z
            tr = not(tr)
            z = a[i]
    su += z
    print(su)
