for _ in range(int(input())):
    n = int(input())
    nums = list(map(int, input().split()))
    pnt1 = 0
    pnt2 = 0
    ans = 0
    while(pnt2 <n):
        if((nums[pnt1]<0 and nums[pnt2] < 0) or (nums[pnt1] > 0 and nums[pnt2] > 0)):
            pnt2+=1
        else:
            ans += max(nums[pnt1:pnt2])
            pnt1 = int(pnt2)
    ans += max(nums[pnt1:pnt2]) if nums[pnt1:pnt2] else 0
    print(ans)
