### main

while line = gets
  line.strip!
  line = gets if line == ''

  sn, dn, m = line.split.map(&:to_i)
  #p [sn, dn, m]

  swts = []
  sn.times do
    ki = gets.to_i
    wps = gets.split.map(&:to_i)

    swti = []
    for i in (0...ki)
      swti << wps[i * 2, 2]
    end
    swts << swti
  end
  #p swts

  fs = gets.split.map(&:to_i)
  #p fs

  ws = (dn + 1).times.map{[0] * (m + 1)}

  for day in (0...dn)
    dws = [0] * (m + 1)

    for swt in swts[fs[day]]
      wi, pi = swt
      m.downto(pi) do |pk|
        dwi = dws[pk - pi] + wi
        dws[pk] = dwi if dws[pk] < dwi
      end
    end

    for pk in (0..m)
      for pu in (0..pk)
        wku = ws[day][pk - pu] + dws[pu]
        ws[day + 1][pk] = wku if ws[day + 1][pk] < wku
      end
    end
    #p ws
  end

  max_w = 0
  min_p = nil

  for i in (0..m)
    if max_w < ws[dn][i]
      max_w = ws[dn][i]
      min_p = i
    end
  end

  puts [max_w, min_p].join(' ')
end