#include using namespace std; #include using namespace atcoder; using ll = int64_t; using ul = uint64_t; using ld = long double; using vi = vector; using vd = vector; using vc = vector; using vs = vector; using vb = vector; using vl = vector; using vvi = vector; using vvd = vector; using vvc = vector; using vvb = vector; using vvl = vector; using mint = modint998244353; using vm = vector; int main() { ll N,R,C; cin >> N >> R >> C; vector> G(N + 1, vector(6)); vl X(N),Y(N),Z(N),S(N); for (int i = 0; i < N; i++) { cin >> X[i]; G[i][0].push_back({i, 1, X[i]}); G[i][3].push_back({i, 4, X[i]}); } for (int i = 0; i < N; i++) { cin >> Y[i]; for (int j = 0; j < 2; j++) { G[i][j].push_back({i, 2, Y[i]}); G[i][j + 3].push_back({i, 5, Y[i]}); } } for (int i = 0; i < N; i++) { cin >> Z[i]; for (int j = 0; j < 3; j++) { G[i][j].push_back({i, j + 3, Z[i]}); } } for (int i = 0; i < N; i++) { cin >> S[i]; for (int j = 3; j < 6; j++) { G[i][j].push_back({N, j, S[i] + C}); G[N][j].push_back({i, j, S[i]}); } } for (int i = 0; i < R; i++) { int u,v; ll W,A,M; cin >> u >> v >> W >> A >> M; vl mod3(3, 1e18); mod3[0] = W; mod3[1] = min(W, A); mod3[2] = min(W, min(A, M)); u--,v--; for (int j = 0; j < 6; j++) { G[u][j].push_back({v, j, mod3[j%3]}); G[v][j].push_back({u, j, mod3[j%3]}); } } vvb abso(N + 1, vb(6, false)); vvl dist(N + 1, vl(6, 1e18)); priority_queue> pq; dist[0][0] = 0; pq.push({0, 0, 0}); while(!pq.empty()) { int now = pq.top()[1],lic = pq.top()[2]; pq.pop(); if (abso[now][lic]) continue; abso[now][lic] = true; for (auto nv : G[now][lic]) { int next = nv[0],nlic = nv[1]; ll cost = nv[2]; if (dist[next][nlic] <= dist[now][lic] + cost) continue; dist[next][nlic] = dist[now][lic] + cost; pq.push({dist[next][nlic], next, nlic}); } } ll ans = 1e18; for (int i = 0; i < 6; i++) { ans = min(ans, dist[N - 1][i]); } cout << ans << endl; return 0; }