### constants

MAX_INT = 1 << 30

### subroutines

def calc_del_mc(n, tbls)
  sts = [[0, 0]]
  to = {}
  prvs = (n - 1).times.map{{}}

  for i in (0...(n - 1))
    tbli = tbls[i]
    to = {}

    for st in sts
      ti, ci = st

      for tbl in tbli
        xij, yij, cij, tfij = tbl

        if tfij && xij >= ti
          ci0 = ci + cij
          if to[yij].nil?
            to[yij] = [yij, ci0]
            prvs[i][yij] = ti
          elsif to[yij][1] > ci0
            to[yij][1] = ci0
            prvs[i][yij] = ti
          end
        end
      end

      sts = to.values.sort
    end
  end

  min_cost = MAX_INT
  min_yi = nil

  for st in sts
    ti, ci = st
    if min_cost >ci
      min_cost = ci
      min_yi = ti
    end
  end

  return nil if min_yi.nil?

  prv_yi = min_yi
  (n - 2).downto(0) do |i|
    for tbl in tbls[i]
      tbl[3] = false if tbl[1] == prv_yi
    end
    prv_yi = prvs[i][prv_yi]
  end

  min_cost
end

### main

loop do
  n = gets.to_i
  break if n == 0

  tbls = []
  (n - 1).times do
    mi = gets.to_i
    tbli = []
    mi.times do
      xij, yij, cij = gets.split.map(&:to_i)
      tbli << [xij, yij, cij, true]
    end
    tbls << tbli.sort
  end
  #p tbls

  g = gets.to_i

  csum = 0
  glen = 0

  while glen < g
    c = calc_del_mc(n, tbls)
    break if c.nil?

    csum += c
    glen += 1
  end

  puts [glen, csum].join(' ')
end