#include using namespace std; using i64 = long long; using pii = pair; const int N = 88, Z = N * 2; int n, m, k, t; pii g[N][N]; i64 dis[N][N][N * 4]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m >> k >> t; for(int i = 0, a, b, c, d; i < k; i ++) { cin >> a >> b >> c >> d; g[a][b] = {c, d}; } memset(dis, 0x3f, sizeof dis); dis[1][1][Z] = 0; using dij = tuple; priority_queue, greater > q; q.push({0, 1, 1, Z}); while(q.size()) { auto [d, i, j, t] = q.top(); q.pop(); if(dis[i][j][t] < d) continue; auto update = [&q](int x, int y, int z, i64 d) { if(x < 1 || x > n || y < 1 || y > m || z < 0 || z >= 4 * N) return; if(d < dis[x][y][z]) { dis[x][y][z] = d; q.push({d, x, y, z}); } }; update(i - 1, j, t + 1, d); update(i + 1, j, t + 1, d); update(i, j - 1, t + 1, d); update(i, j + 1, t + 1, d); update(i, j, t - g[i][j].first + 1, d + g[i][j].second); } cout << (dis[n][m][min(Z + t, 4 * N - 1)] <= 1e18 ? dis[n][m][min(Z + t, 4 * N - 1)] : -1); }