#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using llu = unsigned long long;
using ld = long double;

#define CEIL(x, y) (ll)ceil((ld)(x) / (ld)(y))

#define dbgPR(ds) cout << ds.first << ' ' << ds.second;
#define dbgLST(ds) for(auto it : ds) cout << it << ' ';
#define dbgMP(ds) for(auto it : ds) cout << it.first << ' ' << it.second << '\n';

const double PI = acos(-1.0), g = 9.80665;
const bool unseen = 0;
const ll pinf = 1e18 + 505, ninf = -1e18 - 505;
const int MOD = 1000000007;

int ans = 0;

void rcr(vector<vector<bool>> v, int h, int w, int a, int b)
{
    if(a == 0 && b == 0) {
        bool is = 1;
        for(int i = 0; is && i < h; i++) {
            for(int j = 0; j < w; j++) {
                if(!v[i][j]) {
                    is = 0;
                    break;
                }
            }
        }
        if(is) ans++;
        return;
    }
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            if(!v[i][j]) {
                if(b != 0) {
                    v[i][j] = 1;
                    rcr(v, h, w, a, b - 1);
                    v[i][j] = 0;
                }
                if(a != 0) {
                    if(i < (h - 1)) {
                        v[i][j] = 1;
                        v[i + 1][j] = 1;
                        rcr(v, h, w, a - 1, b);
                        v[i][j] = 0;
                        v[i + 1][j] = 0;
                    }
                    if(j < (w - 1)) {
                        v[i][j] = 1;
                        v[i][j + 1] = 1;
                        rcr(v, h, w, a - 1, b);
                        v[i][j] = 0;
                        v[i][j + 1] = 0;
                    }
                }
                return; 
            }
        }
    }
}


void solve(void)
{
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    vector<vector<bool>> v(h, vector<bool> (w, 0));
    rcr(v, h, w, a, b);    
    cout << ans;
}

int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(nullptr); 

    int testcase = 1;
    // cin >> testcase;
    while(testcase--) {
        solve();
    }    
    return 0;
}
// I've had my share of sand kicked in my face but I've come through
#pragma GCC optimize("Ofast")
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
 
using namespace std;
 
#define int long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define mod (int)(1e9+7)

void solve() {
  int n,m,x,y; cin>>n>>m>>x>>y;
  x--;y--;
  vector<vector<pair<int,pair<int,int>>>> v(n+1);
  for(int i=0;i<m;i++){
    int a,b,t,k; cin>>a>>b>>t>>k;
    a--;b--;
    v[a].pb({b,{t,k}});
    v[b].pb({a,{t,k}});
  }

  set<pair<int,int>> s;
  vector<int> d(n+1,1e18);
  s.insert({0,x});
  d[x]=0;
  while(!s.empty()){
    auto z=*s.begin();
    s.erase(s.begin());

    for(auto i:v[z.second]){
      int time=(((z.first+i.second.second-1)/i.second.second)*i.second.second)+i.second.first;
      if(time<d[i.first]){
        s.erase({d[i.first],i.first});
        d[i.first]=time;
        s.insert({d[i.first],i.first});
      }
    }
  }

  if(d[y]==(1e18))cout<<"-1\n";
  else cout<<d[y]<<'\n';
}
 
int32_t main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}