for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    curr_max = a[0]
    l = []
    for i in a:
        if curr_max > 0 and i > 0:
            curr_max = max(curr_max, i)
        elif curr_max > 0 > i:
            l.append(curr_max)
            curr_max = i
        elif curr_max < 0 and i < 0:
            curr_max = max(curr_max, i)
        elif curr_max < 0 < i:
            l.append(curr_max)
            curr_max = i
    l.append(curr_max)
    #print(l)
    print(sum(l))
