def solve(n, a):
    sign = lambda x:x//abs(x)
    mx = a[0]
    f = a[0]//(abs(a[0]))
    ans = 0
    for i in range(1, n):
        if sign(a[i])==f*-1:
            ans+=mx
            mx = a[i]
            f*=-1
        mx = max(mx, a[i])
    if sign(a[-1])==f:
        ans+=mx
    return ans
def main():
    q = int(input())
    for i in range(q):
        n, a = int(input()), [int(j) for j in input().split()]
        print(solve(n, a))
main()