t = int(input())
for _ in range(t):
    n = int(input())
    a = [int(x) for x in input().split()]
    ans = []
    pos = int(a[0] >0)
    act = a[0]
    for i in range(n):
        if int(a[i]>0) ^ pos:
            # print("cambia",a[i])
            pos = 1- pos
            ans.append(act)
            act = a[i]
        else:
            act = max(act, a[i])
    ans.append(act)
    print(sum(ans))
