for i in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    now = a[0]
    maxx = a[0]
    ans = []
    summ = 0
    for j in a[1:]:
        if maxx < 0 and j > 0:
            summ += maxx
            maxx = j
        elif maxx > 0 and j < 0:
            summ += maxx
            maxx = j
        elif j > maxx:
            maxx = j
    summ += maxx
    print(summ)