def solve(a):
    if a[0]>0:
        s = True
    else:
        s = False
    r = 0
    t = []
    for i in range(len(a)):
        #print(t)
        if (a[i]>0) != s:
            r+=max(t)
            s = not s
            t = []
        t.append(a[i])
    r+=max(t)
    return r

t = int(input())
for i in range(t):
    _ = input()
    a = [int(x) for x in input().split(' ')]
    s = solve(a)
    print(s)