def search_sum(numbers, target, _max, partial=[]):
    s = [sum(x) for x in zip(*partial)]

    # check partial sums
    if(len(s) == 2):
        if s[0] <= target:
            if s[1] > _max[0]:
                _max[0] = s[1]
        if s[0] > target:
            return

    for i in range(len(numbers)):
        n = numbers[i]
        remaining = numbers[i+1:]
        search_sum(remaining, target, _max, partial + [n]) 

# get maximum 
def max_turn_damage(l, is_double = False):
    _max = [0]
    search_sum(l, 3, _max)

    # return values
    if is_double:
        return 2 * _max[0]
    return _max[0]

if __name__ == "__main__":
    # get size
    n = int(input())

    # read lists
    result = 0
    for k in range(n):

        # read data
        arr = []
        size = int(input())
        for _ in range(size):
            arr.append([(int(i)) for i in raw_input().split()])

        result += max_turn_damage(arr, (k + 1) % 5 == 0)
    
    # print result
    print(result)