for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    ans = [a[0]]
    for i in range(1, n):
        if a[i] < 0:
            if ans[-1] < 0:
                ans[-1] = max(a[i], ans[-1])
            else:
                ans.append(a[i])
        else:
            if ans[-1] > 0:
                ans[-1] = max(a[i], ans[-1])
            else:
                ans.append(a[i])
    print(sum(ans))
