for _ in range(input()):
    n = input()
    a = map(int,raw_input().split())
    ans = [a[0]]
    for i in range(1,n):
        if ans[-1]<0 and a[i]<0:
            ans[-1] = max(ans[-1], a[i])
        elif ans[-1]>0 and a[i]>0:
            ans[-1] = max(ans[-1], a[i])
        else:
            ans.append(a[i])

    print sum(ans)
