#include<iostream>
#include<vector>
using namespace std;
const int INF = 1 << 28;
 
int main()
{
  int s, d, m;
  vector< int > w[100], p[100];
  int dp[301];
 
  while(cin >> s >> d >> m){
    for(int i = 0; i < s; i++){
      int k;
      cin >> k;
      w[i].resize(k), p[i].resize(k);
      for(int j = 0 ; j < k; j++){
        cin >> w[i][j] >> p[i][j];
      }
    }
    fill_n( dp, m + 1, 0);
    for(int i = 0 ; i < d ; i++ ){
      int f;
      cin >> f;
      for(int j = 0 ; j < w[f].size(); j++){
        for(int k = m ; k - p[f][j] >= 0; k--){
          dp[k] = max( dp[k], dp[k - p[f][j]] + w[f][j]);
        }
      }
    }
 
    int pos = 0;
    for(int i = 0 ; i <= m ; i++ ){
      if( dp[i] > dp[pos] ) pos = i;
    }
    cout << dp[pos] << " " << pos << endl;
  }
}