def solve():
    n = int(input())
    ar = [int(i) for i in input().split()]

    neg = False if ar[0] < 0 else True
    s = ar[0]

    for i in ar[1:]:
        if neg and i < 0:
            s += i
            neg = False
        elif not neg and i > 0:
            s += i
            neg = True
    
    if (s == 0):
        s = max(ar) + min(ar)
    return s



tc = int(input())
for i in range(tc):
    print(solve())