t = int(input())
for i in range(t) :
    n = int(input())
    s = input().split()
    for j in range(n) :
        s[j] = int(s[j])
    count = 0
    mp = 0
    mn = -100000000
    if s[0]>0 :
        mp = s[0]
        count = count + mp
    elif s[0]<0 :
        mn = s[0]
        count = count + mn
    for j in range(n-1) :
        if (s[j] > 0) and (s[j+1] < 0) :
            mp = 0
            mn = s[j+1]
            count = count + mn
        elif (s[j] < 0) and (s[j + 1] > 0):
            mn = -1000000000
            mp = s[j+1]
            count = count + mp
        elif (s[j] > 0) and (s[j + 1] > 0):
            if s[j+1]>mp:
                count = count - mp
                # print(count)
                mp = s[j+1]
                count = count + mp
        elif (s[j] < 0) and (s[j+1] < 0) :
            if s[j+1]>mn :
                count = count - mn
                # print(count)
                mn = s[j+1]
                count = count + mn
    print(count)

