t = int(input())
for T in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    t = [a[0]]
    ans = 0
    for ai in a:
        if ai*t[0]>0:
            t.append(ai)
        else:
            ans += max(t)
            t = [ai]
    ans += max(t)
    print(ans)
        
