# https://codeforces.com/problemset/problem/1343/C

def positif(n):
    if n > 0:
        return True
    else:
        return False

nb_cases = int(input())
while nb_cases > 0:
    nb_cases -= 1

    n = int(input())
    a = [int(x) for x in input().split()]
    dernier_max = a[0]
    liste = []
    for x in range(1, (len(a))):
        if positif(a[x])==positif(dernier_max):
            if a[x] > 0 and a[x] > dernier_max:
                dernier_max = a[x]
        else:
            liste.append(dernier_max)
            dernier_max = a[x]
    liste.append(dernier_max)
    print(sum(liste))
