for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    s = 0
    if(a[0]>0):
        x = 1
    else:
        x=0
    pp = 0
    for i in range(1,n):
        if(a[i]<0):
            if(x):
                s+=max(a[pp:i])
                pp = i
                x = 0
            else:
                continue
        else:
            if(x):
                continue
            else:
                s+=max(a[pp:i])
                pp = i
                x = 1
    s+=max(a[pp:n])
    print(s)