#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmin(T &a, T b){
    if(a>b){
        a = b;
        return true;
    }
    return false;
}

template<typename T> class CHT
{
private:
    using ptt = pair<T, T>;
    bool check(ptt l1, ptt l2, ptt l3){
        return (l2.first-l1.first)*(l3.second-l2.second)>=(l2.second-l1.second)*(l3.first-l2.first);
    }
    T f(int i, T x){
        return lines[i].first * x + lines[i].second;
    }
public:
    vector<ptt> lines;
    int head;
    CHT(): head(0){};
    void add(T a, T b){
        ptt line(a, b);
        while((int)lines.size() - head >= 2 && check(*(lines.end()-2), lines.back(), line)){
            lines.pop_back();
        }
        lines.emplace_back(line);
    }
    T get(T x){
        int low = -1, high = lines.size() - 1;
        while (high - low > 1) {
        	int mid = (high + low) / 2;
            if(f(mid, x) >= f(mid+1, x)){
                low = mid;
            }else{
                high = mid;
            }
        }
        return f(high, x);
    }
};

CHT<ll> calc(vector<vector<pair<int,ll> > >g,int s,int t){
    int n = g.size();
    vector<vector<ll> > dst(n,vector<ll>(101,1LL<<60));
    priority_queue<pair<ll,pair<int,int> >,vector<pair<ll,pair<int,int> >>,greater<pair<ll,pair<int,int> >>  > pq;
    pq.push(MP(0LL,MP(s,0)));
    dst[s][0] = 0;
    while(!pq.empty()){
        auto xx = pq.top();
        pq.pop();
        int id = xx.second.first;
        int cnt = xx.second.second;
        ll d = xx.first;
        if(dst[id][cnt]!=d)continue;
        for(auto x:g[id]){
            int nxt = x.first;
            if(x.second == -1){
                if(cnt<=99){
                    if(dst[nxt][cnt+1]> d ){
                        dst[nxt][cnt+1] = d;
                        pq.push(MP(d,MP(nxt,cnt+1)));
                    }
                }
            }else{
                if(dst[nxt][cnt]> d + x.second ){
                    dst[nxt][cnt] = d + x.second;
                    pq.push(MP(d+x.second,MP(nxt,cnt)));
                }
            }
        }
    }
    CHT<ll> cht;
    rep(i,101){
        if(dst[t][100-i]!=(1LL<<60))cht.add(100-i,dst[t][100-i]);
    }
    return cht;
} 

void addx(vector<pair<ll,ll> > &lines,vector<ll> &x){
    int n = lines.size();
    for(int i=0;i<n-1;i++){
        ll a = lines[i].first;
        ll b = lines[i].second;
        ll c = lines[i+1].first;
        ll d = lines[i+1].second;
        if(d-b<0)continue;
        x.push_back((d-b)/(a-c)-1);
        x.push_back((d-b)/(a-c));
        x.push_back((d-b)/(a-c) + 1);
    }
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(1){
        int n,m,p,q,t;
        cin >> n >> m >> p >> q >> t;
        if(n==0)break;
        p--;q--;t--;
        vector<vector<pair<int,ll> > >g(n);
        rep(i,m){
            int a,b;
            cin >> a >> b;
            a--;b--;
            string c;
            cin >> c;
            if(c=="x"){
                g[a].push_back(MP(b,-1));
                g[b].push_back(MP(a,-1));
            }else{
                ll k = stoll(c);
                g[a].push_back(MP(b,k));
                g[b].push_back(MP(a,k));
            }
        }
        CHT<ll> c1 = calc(g,p,t);
        CHT<ll> c2 = calc(g,q,t);
        vector<ll> x;
        x.push_back(0LL);
        addx(c1.lines,x);
        addx(c2.lines,x);
        x.push_back(1LL<<50);
        sort(all(x));
        x.erase(unique(all(x)),x.end());
        int mm = x.size();
        ll mi = 1LL<<60;
        rep(i,mm-1){
            if(x[i]<0)continue;
            if(c1.get(x[i]) >= c2.get(x[i]) && c1.get(x[i+1]) <= c2.get(x[i+1]) ){
                ll lo = x[i];
                ll hi = x[i+1];
                while(hi-lo>1){
                    ll mid = (lo+hi)/2;
                    if(c1.get(mid) >= c2.get(mid)){
                        lo = mid;
                    }else{
                        hi = mid;
                    }
                }
                chmin(mi,abs(c1.get(lo)-c2.get(lo)));
                chmin(mi,abs(c1.get(hi)-c2.get(hi)));
            
            }
            if(c1.get(x[i]) <= c2.get(x[i]) && c1.get(x[i+1]) >= c2.get(x[i+1]) ){
                ll lo = x[i];
                ll hi = x[i+1];
                while(hi-lo>1){
                    ll mid = (lo+hi)/2;
                    if(c1.get(mid) <= c2.get(mid)){
                        lo = mid;
                    }else{
                        hi = mid;
                    }
                }
                chmin(mi,abs(c1.get(lo)-c2.get(lo)));
                chmin(mi,abs(c1.get(hi)-c2.get(hi)));
            
            }else{
                chmin(mi,abs(c1.get(x[i])-c2.get(x[i])));
                chmin(mi,abs(c1.get(x[i+1])-c2.get(x[i+1])));
            }
        }
        
        rep(i,mm){
            if(x[i]<0)continue;
            chmin(mi,abs(c1.get(x[i])-c2.get(x[i])));
        }
        cout << mi << endl;
    }
    return 0;
}


Measured memory_bytes: 5924