for _ in range(int(input())):
    n = int(input())
    a = *map(int, input().split()),
    ii = 0
    b = [[] for _ in range(n)]
    b[0].append(a[0])
    for i, j in zip(a, a[1:]):
        if i*j < 0:
            ii += 1
        b[ii].append(j)
    ans = sum(max(i) for i in b if i)
    print(ans)
