#include <bits/stdc++.h>
using namespace std;
struct data {
  int bit;
  int cost;
  int v;
  data() {}
  data(int vv, int bb, int cc) {
    v = vv;
    cost = cc;
    bit = bb;
  }
  bool operator<(const data &dat) const { return cost > dat.cost; }
};
int n, x, y;
int dp[1 << 14][14];
int dp2[14][1001];
int dp3[1 << 14][1001];
int tmp[1001][1001];
int tmp2[1001];
int tmp3[15][1001];
int dist[14][14];
int a[14][301], b[14][301], c[14][301];
void dijk() {
  priority_queue<data> que;
  for (int i = 0; i < (1 << n); i++) {
    for (int j = 0; j < n; j++) {
      dp[i][j] = 100000;
    }
  }
  dp[1][0] = 0;
  que.push(data(0, 1, 0));
  while (que.size()) {
    data d = que.top();
    que.pop();
    if (dp[d.bit][d.v] < d.cost) continue;
    for (int nec = 0; nec < n; nec++) {
      int nbit = d.bit | (1 << nec);
      int ncost = d.cost + dist[d.v][nec];
      if (ncost < dp[nbit][nec]) {
        dp[nbit][nec] = ncost;
        que.push(data(nec, nbit, ncost));
      }
    }
  }
}
int main(void) {
  scanf("%d%d%d", &n, &x, &y);
  for (int i = 0; i < n; i++) {
    int k;
    scanf("%d", &k);
    for (int j = 0; j < k; j++) {
      scanf("%d%d%d", &a[i][j], &b[i][j], &c[i][j]);
    }
    memset(tmp, 0, sizeof(tmp));
    for (int j = 0; j < k; j++) {
      memset(tmp3, 0, sizeof(tmp3));
      for (int bit = 0; bit < (1 << n); bit++) {
        if (!(bit >> i & 1)) continue;
        for (int cs = 0; cs <= y; cs++) {
          tmp3[0][cs] = dp3[bit][cs];
        }
        int cnt2 = 0;
        for (int ncs = 0; ncs <= 10; ncs++) {
          int cs = min(c[i][j], (int)(1 << ncs));
          c[i][j] -= cs;
          cnt2++;
          for (int l = 0; l <= y; l++) {
            tmp3[cnt2][l] = max(tmp3[cnt2][l], tmp3[cnt2 - 1][l]);
            if (l + cs * a[i][j] > y) continue;
            tmp3[cnt2][l + cs * a[i][j]] = max(
                tmp3[cnt2][l + cs * a[i][j]], tmp3[cnt2 - 1][l] + b[i][j] * cs);
          }
        }
        for (int cs = 0; cs <= y; cs++) {
          dp3[bit][cs] = tmp3[cnt2][cs];
          if (cs > 0) dp3[bit][cs] = max(dp3[bit][cs - 1], dp3[bit][cs]);
        }
      }
    }
    for (int j = 0; j <= y; j++) {
      dp2[i][j] = tmp[k][j];
    }
    for (int j = 1; j <= y; j++) {
      dp2[i][j] = max(dp2[i][j], dp2[i][j - 1]);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      scanf("%d", &dist[i][j]);
    }
  }
  dijk();
  for (int i = 0; i < (1 << n); i++) {
    for (int j = 1; j <= y; j++) {
      dp3[i][j] = max(dp3[i][j], dp3[i][j - 1]);
    }
  }
  int res = 0;
  for (int i = 0; i < (1 << n); i++) {
    int yosan = 0;
    for (int j = 0; j < n; j++) {
      yosan = max(yosan, x - dp[i][j] - dist[j][0]);
    }
    yosan = min(y, yosan);
    res = max(res, dp3[i][yosan]);
  }
  printf("%d\n", res);
  return 0;
}
