#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
#define ALL(v) v.begin(),v.end()
#define sz(v) (ll)v.size()
const ll INF = 1e18;

// E - Train

ll Ceil(ll a, ll b) {
    if(a%b == 0) return a/b;
    else return (a+b)/b;
}

int main() {
    ll n, m, x, y;
    cin >> n >> m >> x >> y;
    vector<vector<pair<ll, ll>>> G(n+1); //ressya tyoutenn
    vector<ll> t(m), k(m);
    for(ll i = 0; i < m; i++) {
        ll a, b;
        cin >> a >> b;
        G[a].push_back({i, b});
        G[b].push_back({i, a});
        cin >> t[i] >> k[i];
    }
    vector<ll> dis(n+1, INF); // dis[i]:xからiまでの最短経路
    dis[x] = 0;
    priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;
    pq.push({0, x});
    while(!pq.empty()){
        pair<ll, ll> p = pq.top();
        pq.pop();
        ll v = p.second;
        if(dis[v] < p.first) continue;
        for(auto &e : G[v]){
            if(dis[e.second] > Ceil(dis[v],k[e.first])*k[e.first]+t[e.first]){
                dis[e.second] = Ceil(dis[v],k[e.first])*k[e.first]+t[e.first];
                pq.push({dis[e.second], e.second});
            }
        }
    }
    if(dis[y] == INF) cout << -1 << endl;
    else cout << dis[y] << endl;

    return 0;
} 
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <unordered_map>
#include <vector>
#include <queue>
#include <set>
#include <bitset>
#include <cmath>

#define P 131

#define lc u << 1
#define rc u << 1 | 1

using namespace std;
typedef long long LL;
typedef pair<LL,int> PII;
const int N = 100010,M = N * 2;
const LL INF = 0x3f3f3f3f3f3f3f3fll;
int h[N],ne[M],e[M],idx;
LL dist[N],w[M],f[M];
bool st[N];
int n,m,x,y;

void add(int a,int b,int c,int d)
{
    e[idx] = b,w[idx] = c,f[idx] = d,ne[idx] = h[a],h[a] = idx ++;
}

LL dijkstra()
{
    memset(dist,0x3f,sizeof dist);
    dist[x] = 0;
    priority_queue<PII,vector<PII>,greater<PII>> q;
    q.push(make_pair(0,x));
    while(q.size())
    {
        auto t = q.top();
        q.pop();
        int ver = t.second;
        LL distance = t.first;
        if(st[ver]) continue;
        st[ver] = true;
        // cout << ver << " "<< distance << endl;
        for(int i = h[ver];~i;i = ne[i])
        {
            int j = e[i];
            if(dist[j] > (distance + f[i] - 1) / f[i] * f[i] + w[i])
            {
                dist[j] = (distance + f[i] - 1) / f[i] * f[i] + w[i];
                q.push(make_pair(dist[j],j));
            }
        }
    }
    if(dist[y] >= INF) return -1;
    return dist[y];
}

void solve()
{
    scanf("%d%d%d%d",&n,&m,&x,&y);
    memset(h,-1,sizeof h);
    while(m --)
    {
        int a,b,t,k;
        scanf("%d%d%d%d",&a,&b,&t,&k);
        add(a,b,t,k);
        add(b,a,t,k);
    }
    printf("%lld\n",dijkstra());
}

int main()
{
    #ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #else
    #endif // LOCAL
    int T = 1;
    // init();
    // scanf("%d",&T);
    while(T --)
    {
        // scanf("%lld%lld",&n,&m);
        solve();
        // test();
    }
    return 0;
}