numcases = int(input())

for i in range(numcases):
    alength = int(input())
    a = list(map(int, input().split()))
    t = a[0]
    ans = []
    for i in range(alength - 1):
        if a[i]*a[i + 1] > 0:
            if a[i + 1] > t:
                t = a[i + 1]
        else:
            ans.append(t)
            t = a[i + 1]
    ans.append(t)
    print(sum(ans))