t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    alter = []
    for i in range(n):
        if len(alter) > 0 and a[i] / alter[-1] >0:
            if a[i] > alter[-1]:
                alter[-1] = a[i]
        else:
            alter.append(a[i])

    print(sum(alter))
        

