for _ in range(int(input())):
    n = int(input())
    arr = list(map(int,input().split()))
    cur = arr[0] 
    s = 0
    for i in range(1,n):
        # print('cur',cur,arr[i])
        if (arr[i]<0 and cur>0) or (arr[i]>0 and cur<0):
            s+=cur
            cur = arr[i]
            continue
        cur = max(arr[i],cur)
    s+=cur
    print(s)