
var a = [[1,2]]
a + [[1]]

func totalUreshisa (rakudaList: [Int], uresiList: [[Int]]) -> Int {
    var total = 0
    for i in 1...rakudaList.count {
        if rakudaList[i-1] <= uresiList[i-1][0] {
            total += uresiList[i-1][1]
        } else {
            total += uresiList[i-1][2]
        }
    }
    return total
}

func allArrayOfRakuda (rakudaNum: Int) -> [[Int]] {
    let rakudaLeft = Array(1...rakudaNum)
    func recursiveF (rakudaLeft: [Int], rakudaList: [Int]) -> [[Int]] {
        var new = [[Int]]()
        if rakudaLeft.count == 0 {
            return [rakudaList]
        }
        for i in 1...rakudaLeft.count {
            var chooseList = rakudaLeft
            let chozen = chooseList.remove(at: i-1)
            new += recursiveF(rakudaLeft: chooseList, rakudaList: rakudaList + [chozen])
        }
        return new
    }
    return recursiveF(rakudaLeft: rakudaLeft, rakudaList: [])
}

func main() {
    let t = Int(readLine()!)!
    for _ in 1...t {
        let n = Int(readLine()!)!
        var uresisa = [[Int]]()
        for _ in 1...n {
            uresisa.append(readLine()!.split(separator: " ").map{Int($0)!})
        }
        var maxUresisa = 0
        for item in allArrayOfRakuda(rakudaNum: n) {
            let aTotalUresisa = totalUreshisa(rakudaList: item, uresiList: uresisa)
            if maxUresisa < aTotalUresisa {
                maxUresisa = aTotalUresisa
            }
            
        }
        print(maxUresisa)
    }
}

main()
