for t in range(int(input())):
    n=int(input())
    a=[int(x) for x in input().split()]
    c=0
    s=0
    v=-99999999999
    for i in range(n):
        if i==0:
            if a[i]>0:
                c=1
                v=max(v,a[i])
            else:
                c=0
                v=max(v,a[i])
        else:
            if a[i]>0:
                if c==1:
                    v=max(v,a[i])
                else:
                    c=1
                    s=s+v
                    v=a[i]
            else:
                if c==0:
                    v=max(v,a[i])
                else:
                    c=0
                    s=s+v
                    v=a[i]
    s=s+v
    print(s)