def getsign(n):
    if n>0:
        return 1
    else:
        return 0

t = int(input())
for i in range(t):
    n = int(input())
    data = list(map(int , input().split()))
    cursign = getsign(data[0])
    if cursign:
        curmax = data[0]
    else:
        curmin = data[0]
    ans = 0
    
    for i in range(1 , len(data)):
        if getsign(data[i]) == cursign:
            if cursign:
                if data[i] > curmax:
                    curmax = data[i]
            else:
                if data[i] > curmin:
                    curmin = data[i]
        else:
            if cursign:
                ans += curmax
                curmin = data[i]
            else:
                ans += curmin
                curmax = data[i]
            cursign = abs(cursign - 1)
    if cursign:
        ans += curmax
    else:
        ans += curmin
    print(ans)