for i in range(int(input())):
    n = int(input())
    arr = list(map(int,input().split()))

    neg = []
    pos = []

    final = []

    for j in range(len(arr)):
        if(arr[j] < 0):
            if(len(pos) > 0):
                final.append(max(pos))
                pos = []
            neg.append(arr[j])

        else:
            if(len(neg) > 0):
                final.append(max(neg))
                neg = []
            pos.append(arr[j])

    if(len(pos) > 0):
        final.append(max(pos))
    else:
        final.append(max(neg))

    print(sum(final))        