from itertools import*
for s in range(int(input())):
    a = int(input())
    b = [x for x in input().split()]
    g = 0
    for _, v in groupby(b, str.isdigit):
        g += max(map(int,v))
    print(g)