for _ in range (int(input())) :
    n = int(input())
    l=[int(x) for x in input().split()]
    m = []
    maxi = -1000000000000000000000000000000000000
    if l[0] > 0 :
        c = 1 
    else :
        c = 0 
    for i in range (n) :
        if c == 1 and l[i] > 0 :
            maxi = max(maxi , l[i])
            c = 1 
        elif c == 1 and l[i] < 0 :
            m.append(maxi)
            maxi = l[i]
            c=0
        elif c == 0 and l[i] < 0 :
            maxi = max(maxi , l[i])
            c=0
        else :
            m.append(maxi)
            maxi = l[i]
            c=1 
    if len(m) != 0 :
        if max(l[-1] , m[-1]) > 0 and min(l[-1],m[-1]) < 0 :
            m.append(maxi)
        print(sum(m))
    else :
        print(max(l))