#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;

int n;
int dp[14][1001];
int dist[14][14];
int dcost[(1 << 14)][14];
int sumcost[1 << 14];

int c1[1 << 7][1001];
int c2[1 << 7][1001];
void solve() {
	cin >> n; int x, y; cin >> x >> y;
	//start_napzack
	rep(i, n) {
		int k; cin >> k;
		rep(j, y+1) {
			dp[i][j] = -mod;
		}
		dp[i][0] = 0;
		rep(j, k) {
			//cost,val,num
			int a, b, c; cin >> a >> b >> c;
			rep(l, a) {
				if (l > y)continue;
				priority_queue<P> q;
				q.push({ dp[i][l],0 });
				int ad = 0;
				for (int loc = l + a; loc <= y; loc += a) {
					ad += b;
					P p = q.top();
					while (true) {
						if (loc / a - p.second > c) {
							q.pop(); p = q.top();
						}
						else break;
					}
					q.push({ dp[i][loc] - ad,loc / a });
					dp[i][loc] = max(dp[i][loc], p.first + ad);
				}
			}
		}
	}
	//end_napzack

	rep(i, n) {
		rep(j, n) {
			cin >> dist[i][j];
		}
	}
	rep(i, (1 << n))rep(j, n)dcost[i][j] = mod;
	dcost[1][0] = 0;
	for (int i = 1; i < (1 << n);i+=2) {
		rep(j, n) {
			rep(k, n) {
				if (i&(1 << k))continue;
				int ni = i ^ (1 << k);
				dcost[ni][k] = min(dcost[ni][k], dcost[i][j] + dist[j][k]);
			}
		}
	}
	rep(i, (1 << n)) {
		sumcost[i] = mod;
		rep(j, n) {
			sumcost[i] = min(sumcost[i], dcost[i][j] + dist[j][0]);
		}
	}
	int h = n / 2; int h2 = n - h;
	rep(i, (1 << h)) {
		rep(j, y + 1)c1[i][j] = -mod;
		c1[i][0] = 0;
		rep(j, h) {
			if (i&(1 << j)) {
				per(k, y + 1) {
					if (c1[i][k] < 0)continue;
					rep(l, y + 1) {
						if (k + l > y)break;
						c1[i][k + l] = max(c1[i][k + l], c1[i][k] + dp[j][l]);
					}
				}
			}
		}
		rep1(j, y) {
			c1[i][j] = max(c1[i][j], c1[i][j - 1]);
		}
	}
	rep(i, (1 << h2)) {
		rep(j, y + 1)c2[i][j] = -mod;
		c2[i][0] = 0;
		rep(j, h2) {
			if (i&(1 << j)) {
				per(k, y + 1) {
					if (c2[i][k] < 0)continue;
					rep(l, y + 1) {
						if (k + l > y)break;
						c2[i][k + l] = max(c2[i][k + l], c2[i][k] + dp[j + h][l]);
					}
				}
			}
		}
		rep1(j, y) {
			c2[i][j] = max(c2[i][j], c2[i][j - 1]);
		}
	}
	int mid = (1 << h);
	int ans = 0;
	for (int i = 1; i < (1 << n); i += 2) {
		int sc = sumcost[i];
		sc = x - sc;
		if (sc > y)sc = y;
		int r = sc;
		int li = i % mid; int ri = i / mid;
		rep(j, r + 1) {
			int s = c1[li][j] + c2[ri][r - j];
			ans = max(ans, s);
		}
	}
	cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(5);
	//while (cin >> n>>h>>m>>s,n)solve();
	solve();
	//stop
	return 0;
}

