for t in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    ans = 0
    curr = a[0]
    for i in range(1, n):
        if a[i]*curr > 0:
            if a[i] > curr:
                curr = a[i]
                continue
        else:
            ans = ans + curr
            curr = a[i]

    print(ans+curr)
