for t in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))

    s = 0
    l = (0 if a[0] < 0 else 1)

    m = a[0]

    for i in range(1, n):
        if l == 0:
            if a[i] < 0:
                if a[i] > m:
                    m = a[i]
            else:
                l = 1
                s += m
                m = a[i]
        else:
            if a[i] >= 0:
                if a[i] > m:
                    m = a[i]
            else:
                l = 0
                s += m
                m = a[i]

    s += m

    print(s)