from sys import stdin,stdout
read,write = stdin.readline,stdout.write
t = int(read())
for i in range(t):
    n = int(read())
    arr = map(int,read().split())

    groups = [[arr[0]]]
    prev = arr[0]
    for elem in arr[1:]:
        if elem >= 0 and prev >= 0 or elem < 0 and prev <0:
            groups[-1].append(elem)
        else:
            groups.append([elem])
        prev = elem

    ans = 0 
    for group in groups:
        ans += max(group)
    print(ans)