#include using namespace std; using ll = long long; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); ll ans = 1e18; ll n,m,k,t; cin>>n>>m>>k>>t; vector>> use(n,vector>(m)); for(int i = 0;i>a>>b>>c>>d; a--;b--; use[a][b] = make_pair(c,d); } using dat = pair>; priority_queue,vector>,greater>> que; map vis; map memo; que.push(make_pair(0,make_pair(0,make_pair(0,0)))); int dx[] = {1,-1,0,0}; int dy[] = {0,0,1,-1}; while(!que.empty()){ auto now = que.top(); que.pop(); if(vis[now.second]++) continue; int ni = now.second.second.first; int nj = now.second.second.second; if(ni==n-1&&nj==m-1){ if(now.second.first>t) continue; ans = min(ans,now.first); continue; } for(int k = 0;k<4;k++){ int nni = ni + dx[k]; int nnj = nj + dy[k]; if(nni<0||nnj<0||nni>=n||nnj>=m) continue; ll nxt = now.second.first; nxt++; ll cost = now.first; if(use[nni][nnj].first!=0){ nxt++; nxt -= use[nni][nnj].first; cost += use[nni][nnj].second; } if(nxt<=-7000) nxt = -7000; if(nxt>=7000) nxt = 7000; dat will = make_pair(nxt,make_pair(nni,nnj)); if(memo.find(will)!=memo.end()&&memo[will]<=cost) continue; memo[will] = cost; que.push(make_pair(cost,will)); } } if(ans==1e18) ans = -1; cout<