t=int(input())
while(t>0):
    t-=1
    n=int(input())
    a=[int(i) for i in input().split()]
    ans = 0
    if a[0]>0:
        flag = 1
    else:
        flag = 0
    maxi = a[0]
    maxsum = 0
    for i in range (n):
        if flag == 0 and a[i]>0:
            flag = 1
            maxsum+=maxi
            maxi = a[i]
            continue
        if flag == 1 and a[i]<0:
            flag = 0
            maxsum+=maxi
            maxi = a[i]
            continue
        if a[i]>maxi:
            maxi = a[i]
    maxsum+=maxi
    print(maxsum)