tc = int(input())
for i in range(tc):
    res = 0
    n = int(input())
    lis = list(map(int, input().split()))
    temp_lis = []
    for i in lis:
        if len(temp_lis) == 0:
            temp_lis.append(i)
            parity = 0 if i > 0 else 1

        else:
            new_p = 0 if i > 0 else 1
            if (new_p == parity):
                temp_lis.append(i)

            else:
                res += max(temp_lis)
                temp_lis = [i]
                parity = 0 if i > 0 else 1
    
    if (len(temp_lis) != 0):
        res += max(temp_lis)

    print (res)
