t = int(input())
for k in range(t):
    n = int(input())
    a = list(map(int,input().split()))
    ans = a[0]
    v = a[0]
    for i in range(0,n-1):
        if v>0 and a[i+1]<0:
            ans = ans+a[i+1]
            v = a[i+1]
        if v>0 and a[i+1]>0:
            if a[i+1]>v:
                ans = ans-v+a[i+1]
                v = a[i+1]
            else:
                pass
        if v<0 and a[i+1]>0:
            ans = ans +a[i+1]
            v = a[i+1]
        if v<0 and a[i+1]<0:
            if a[i+1]>v:
                ans = ans-v+a[i+1]
                v = a[i+1]
            else:
                pass
    print(ans)