for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    yes = 0
    no = 0
    mu = 0
    pl = 0
    if a[0] > 0:
        no = 1
        pl = a[0]
    else:
        yes = 1
        mu = a[0]
    ans = 0
    for i in range(1, n):
        if a[i] > 0 and yes == 1:
            ans += mu
            no = 1
            yes = 0
            pl = a[i]
        elif a[i] < 0 and no == 1:
            ans += pl
            no = 0
            yes = 1
            mu = a[i]
        elif a[i] > 0 and yes == 0:
            if a[i] > pl:
                pl = a[i]
        elif a[i] < 0 and no == 0:
            if a[i] > mu:
                mu = a[i]
    if a[-1] > 0:
        ans += pl
    elif a[-1] < 0:
        ans += mu
    print(ans)