for _ in range(int(input())):
    n = int(input())
    x = [int(w) for w in input().split()]
    y = []
    prev = 0
    for i in x:
        if (prev<0 and i>0) or (prev>0 and i<0) or prev == 0:
            y.append([i])
        else:
            y[-1].append(i)
        prev = i
    ans = 0
    for i in y:
        ans += max(i)
    print(ans)