t = int(input())

def solving(l):
    is_nat = True if l[0] >= 0 else False
    res_l = []
    loc_l = []
    for i in l:
        if is_nat:
            if i >= 0:
                loc_l.append(i)
            else:
                res_l.append(loc_l)
                loc_l = [i]
                is_nat = False
        else:
            if i < 0:
                loc_l.append(i)
            else:
                res_l.append(loc_l)
                loc_l = [i]
                is_nat = True
    res_l.append(loc_l)
    the_res_l = []
    for i in res_l:
        the_res_l.append(max(i))
    return sum(the_res_l)


for i in range(t):
    input()

    l = list(map(int, input().split()))
    print(solving(l))