#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<iomanip>
//<< setprecision(5)
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define dme cout<<-1<<endl;return 0
const int mod=1000000007;
const int big=1e9+10;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}

int main(void){
	int i,j,l,n,X,Y;cin>>n>>X>>Y;
	int ido[14][14];
	static int zyu[16384][14];//????????????,??????????????£??????
	array<vector<pair<int,int>>,14>daga;
	
	for(i=0;i<n;i++){
		int k;cin>>k;daga[i];
		for(j=0;j<k;j++){
			int a,b,c;cin>>a>>b>>c;
			int ho=1;
			while(ho<c){daga[i].pub(mp(a*ho,b*ho));c-=ho;ho*=2;}
			daga[i].pub(mp(a*c,b*c));
		}
	}
	for(i=0;i<14;i++){for(j=0;j<14;j++){ido[i][j]=big;}}
	for(i=0;i<n;i++){for(j=0;j<n;j++){cin>>ido[i][j];}}
	for(l=0;l<n;l++){
		for(i=0;i<n;i++){for(j=0;j<n;j++){mineq(ido[i][j],ido[i][l]+ido[l][j]);}}
	}
	
	//wf
	for(i=0;i<16384;i++){for(j=0;j<14;j++){zyu[i][j]=big;}}
	zyu[0][0]=0;
	for(i=0;i<16384;i++){//?????????
		for(j=0;j<14;j++){//????????????
			if((i&(1<<j))==0){continue;}//????????????????????????
			for(l=0;l<14;l++){//????????¢?´¢
				//if(l!=0&&(i&(1<<l))==0){continue;}//????????????????????????
				mineq(zyu[i][j],zyu[i-(1<<j)][l]+ido[l][j]);
			}
		}
	}
	//?????????dp??¨?????????
	//for(i=0;i<64;i++){cout<<"de i="<<i<<" zyu[i][0]="<<zyu[i][0]<<endl;}
	static array<int,1001> maesak[128];
	static array<int,1001> atosak[128];
	for(i=0;i<128;i++){for(j=0;j<=1000;j++){maesak[i][j]=0;atosak[i][j]=0;}}
	
	for(i=1;i<128;i++){//?????§???????????????????§£???
		int dco=0;//??????????????????
		int ho=1;
		while(ho<=i){ho*=2;dco++;}
		ho/=2;dco--;
		maesak[i]=maesak[i-ho];
		for(l=0;l<daga[dco].size();l++){
			int a=daga[dco][l].fir,b=daga[dco][l].sec;
			for(j=1000-a;j>=0;j--){maxeq(maesak[i][j+a],maesak[i][j]+b);}
		}
		for(j=0;j<1000;j++){maxeq(maesak[i][j+1],maesak[i][j]);}//????§?????§£
	}
	for(i=1;i<128;i++){//????????§???????????????????§£???
		int dco=7;//?????????????????? ??????????????§
		int ho=1;
		while(ho<=i){ho*=2;dco++;}
		ho/=2;dco--;
		atosak[i]=atosak[i-ho];
		for(l=0;l<daga[dco].size();l++){
			int a=daga[dco][l].fir,b=daga[dco][l].sec;
			for(j=1000-a;j>=0;j--){maxeq(atosak[i][j+a],atosak[i][j]+b);}
		}
		for(j=0;j<1000;j++){maxeq(atosak[i][j+1],atosak[i][j]);}//????§?????§£
	}
	//?????????????????????????????????
	
	int ans=0;
	for(i=0;i<16384;i++){
		int kae=min(Y,X-zyu[i][0]);//????????????
		int mae=i&63;int ato=i>>7;
		for(j=0;j<=kae;j++){
			maxeq(ans,maesak[mae][j]+atosak[ato][kae-j]);
		}
	}
	cout<<ans<<endl;
	return 0;
}