### 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

  dswts = []
  for f in fs
    dswts += swts[f]
  end
  #p dswts

  ws = [0] * (m + 1)

  for dswt in dswts
    wi, pi = dswt

    pws = ws.clone

    for pk in (0..m)
      if pk >= pi
        wk = pws[pk - pi] + wi
        ws[pk] = wk if ws[pk] < wk
      end
    end
  end
  #p ws

  max_w = 0
  min_p = nil

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

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