for _ in range(int(input())):
    n, a = int(input()), [int(x) for x in input().split()]
    x, i = [a[0]], 0
    for row in a[1:]:
        if row<0 and x[i]<0 or row>=0 and x[i]>=0: x[i] = max(x[i], row)
        else: i+=1; x += [row]
    print(sum(x))