from itertools import groupby
for _ in range(int(input())):
    n = int(input())
    arr = [int(i) for i in input().split()]
    lst = [list(j) for i, j in groupby(arr, key=lambda x: x > 0)]
    print(sum(max(i) for i in lst))




