def change(sign):
    if sign == -1:
        return 1
    else:
        return -1


def main():
    t = int(input())
    for _ in range(t):
        n = int(input())
        a = list(map(int, input().split()))
        temp = []
        if a[0] < 0:
            sign = -1
        else:
            sign = 1
        ans = 0
        i = 0
        while i < n:
            if a[i] * sign > 0:
                temp.append(a[i])
                i += 1
            else:
                sign = change(sign)
                ans += max(temp)
                temp = []
                continue
        else:
            ans += max(temp)    
        print(ans)

main()