#include<ctime>
#include<queue>
#include<cstdio>
#include<cctype>
#include<cstring>
#define ll long long
const ll N=2e5+10;
using namespace std;
ll read() {
	char c;
	ll x=0,f=1;
	while(!isdigit(c=getchar()))
		f-=2*(c=='-');
	while (isdigit(c)){
		x=x*10+(c-48)*f;
		c=getchar();
	}
	return x;
}
struct edge{
	ll to,t,k,nxt;
	edge(ll a=0,ll b=0,ll c=0,ll d=0){
		to=a;
		t=b;
		k=c;
		nxt=d;
	}
};
edge e[N];
ll n,m,x,y,u,v,t,k;
ll tot,head[N],dis[N],vis[N];
void add(ll u,ll v,ll t,ll k){
	e[++tot]=edge(v,t,k,head[u]);
	head[u]=tot;
}
ll SPFA(){
	queue<ll>q;
	memset(dis,63,sizeof(dis));
	dis[x]=0;
	vis[x]=1;
	q.push(x);
	while(!q.empty()){
		ll u=q.front();
		q.pop();
		vis[u]=0;
		for(ll i=head[u];i;i=e[i].nxt){
			ll v=e[i].to;
			ll t=e[i].t;
			ll k=e[i].k;
			ll d=(dis[u]+k-1)/k*k;
			if(dis[v]>d+t){
				dis[v]=d+t;
				if(!vis[v]){
					vis[v]=1;
					q.push(v);
				}
			}
		}
	}
	if(dis[y]==dis[0])
		return -1;
	return dis[y];
}
int main() {
	#ifndef ONLINE_JUDGE
	freopen("E.in","r",stdin);
	freopen("E.out","w",stdout);
	#endif
	clock_t t1=clock();
	//--------
	n=read();
	m=read();
	x=read();
	y=read();
	for(ll i=1;i<=m;++i){
		u=read();
		v=read();
		t=read();
		k=read();
		add(u,v,t,k);
		add(v,u,t,k);
	}
	printf("%lld",SPFA());
	//--------
	clock_t t2=clock();
	fprintf(stderr,"time:%0.3lfs",1.0*(t2-t1)/CLOCKS_PER_SEC);
	return 0;
}
#include <bits/stdc++.h>
using namespace std;

void DFS(int u, vector<set<int>>& edges, vector<set<int>>& to) {
    while (!edges[u].empty()) {
        int v = *(edges[u].begin());
        // u -> v
        edges[u].erase(v);
        edges[v].erase(u);
        to[u].insert(v);
        DFS(v, edges, to);
    }
    return;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, M;
    cin >> N >> M;
    vector<int> a(M), b(M);
    for (int i = 0; i < M; ++i) {
        cin >> a[i] >> b[i];
        --a[i];
        --b[i];
    }
    vector<int> c(N);
    for (int i = 0; i < N; ++i) {
        cin >> c[i];
    }
    vector<int> ans(M, 0); // 0 : <-, 1 : ->
    vector<set<int>> edges(N);
    for (int i = 0; i < M; ++i) {
        if (c[a[i]] < c[b[i]]) {
            ans[i] = 0;
        } else if (c[a[i]] > c[b[i]]) {
            ans[i] = 1;
        } else {
            edges[a[i]].insert(b[i]);
            edges[b[i]].insert(a[i]);
        }
    }
    vector<set<int>> to(N);
    for (int i = 0; i < N; ++i) {
        DFS(i, edges, to);
    }
    for (int i = 0; i < M; ++i) {
        if (to[a[i]].count(b[i])) {
            ans[i] = 1;
        }
    }
    for (int i = 0; i < M; ++i) {
        if (ans[i] == 0) {
            cout << "<-\n";
        } else {
            cout << "->\n";
        }
    }
    return 0;
}