for _ in range(int(input())):
    n = int(input())
    a =[*map(int, input().split())]
    ans=0
    i = 0
    while i < n:
        if a[i] < 0:
            tmp = a[i]
            while i < n and a[i] < 0:
                tmp = max(tmp, a[i])
                i += 1
        else:
            tmp = a[i]
            while i < n and a[i] > 0:
                tmp = max(tmp,a[i])
                i += 1
        ans += tmp
    print(ans)