import math

def solve(n,ar):
    best = ar[0]
    track = []
    if n == 1:
        print('0')
        return

    for i in range(1,n):
        if math.copysign(1,best) == math.copysign(1,ar[i]):
            if ar[i] > 0:
                best = max(ar[i],best)

            else:
                best = max(ar[i],best)

            if i == n-1:
                track.append(best)

        else:
            track.append(best)
            best = ar[i]
            if i == n - 1:
                track.append(best)



    print(sum(track))
    return


if __name__ == '__main__':
    t = int(input())

    for _ in range(t):
        n = int(input())
        ar = list(map(int, input().split()))

        solve(n,ar)