for _ in range(int(input())): 
            n = int(input())
            a =list(map(int , input().split()))
            m = a[0]
            s= 0 
            if (n ==1):
                print(m)
            else : 
                for i in range(1,n) : 
                            if ( a[i] > 0 ) :
                                        if(m < 0 ):
                                                    s+=m  
                                                    m = a[i]
                                        else :
                                                    if(a[i] > m) :
                                                                m = a[i]
                            else : 
                                        if (m > 0):
                                                    s+=m  
                                                    m = a[i]
                                        else :
                                                    if(a[i] > m) :
                                                                m = a[i] 
                            if ( i == (n-1)):
                                    s+=m 
                print(s)