#include #define overload(a,b,c,d,...) d #define rep1(a) for(ll _=0;_<(ll)a;++_) #define rep2(i,a) for(ll i=0;i<(ll)a;++i) #define rep3(i,a,b) for(ll i=(ll)a;i<(ll)b;++i) #define rep(...) overload(__VA_ARGS__,rep3,rep2,rep1)(__VA_ARGS__) #define rrep1(i,a) for(ll i=(ll)a-1;i>=0;--i) #define rrep2(i,a,b) for(ll i=(ll)b-1;i>=(ll)a;--i) #define rrep(...) overload(__VA_ARGS__,rrep2,rrep1)(__VA_ARGS__) #define eb emplace_back #define pb push_back #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() #define lb(v,x) (lower_bound(all(v),x)-(v).begin()) #define ub(v,x) (upper_bound(all(v),x)-(v).begin()) using namespace std; using ll=long long; using vl=vector; using ld=long double; using i128=__int128_t; templateinline static constexpr bool chmin(T&a,const U&b){return (a>b?a=b,true:false);} templateinline static constexpr bool chmax(T&a,const U&b){return (a::max()/2; struct IOSetup{IOSetup(){ios::sync_with_stdio(false);cin.tie(nullptr);}}; static constexpr ll mod=998244353; int main(){ ll n,m,x;cin>>n>>m>>x; vector>>g(n); rep(i,m){ ll u,v,c,t;cin>>u>>v>>c>>t; u--,v--; g[u].pb({v,c,t}); g[v].pb({u,c,t}); } vector>dist(n,{inf,inf}); dist[0]={0,0}; priority_queue,ll>,vector,ll>>,greater<>>pq; pq.push({dist[0],0}); while(!pq.empty()){ auto [d,v]=pq.top();pq.pop(); if(dist[v]nxt={dist[v].first+t,dist[v].second+c}; nxt.first+=nxt.second/x; nxt.second%=x; if(chmin(dist[u],nxt))pq.push({dist[u],u}); } } ll ans=dist[n-1].first+(dist[n-1].second==0?0:1); if(ans>=inf){ cout<<-1<