import math
for _ in range(int(input())):
    n = int(input())
    a = list(map(int,input().split()))
    i = 1
    arr = [a[0]]
    while i<n:
        if arr[-1]<0 and a[i]<0:
            if arr[-1]<a[i]:
                del arr[-1]
                arr.append(a[i])
        elif arr[-1]>=0 and a[i]>=0:
            if arr[-1]<a[i]:
                del arr[-1]
                arr.append(a[i])
        else:
            arr.append(a[i])
        i+=1
    print(sum(arr))