//Let's join Kaede Takagaki Fan Club !!
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#define int long long
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define a first
#define b second
#define fi first
#define sc second
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
#define si(x) int(x.size())

#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif

template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b;return true;}else return false;}
template<class t,class u> bool chmin(t&a,u b){if(b<a){a=b;return true;}else return false;}

template<class t> using vc=vector<t>;

template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
	return os<<"{"<<p.fi<<","<<p.sc<<"}";
}

template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
	cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
const ll mod = 1000000007;//998244353
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
template<class T>
void add(T&a,T b){
	a+=b;
	if(a >= mod) a-=mod;
}
ll modpow(ll x,ll n){
	ll res=1;
	while(n>0){
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}
template<class T> using mat = vc<vc<T>>;

template<class T>
mat<T> operator*(mat<T> a, mat<T> b){
	if(a.empty() || b.empty()) return mat<T>();
	int n = a.size();
	int m = b[0].size();
	int len = a[0].size();
	assert(len == b.size());
	mat<T>ret(n);
	rep(i, n) ret[i] = vc<T>(m);
	
	rep(i, n) rep(j, len) rep(k, m){
		ll add = (ll)(a[i][j]) * b[j][k];
		add %= mod;
		ret[i][k] += add;
		if(ret[i][k] >= mod) ret[i][k] -= mod;
	}
	return ret;
}

void solve(){
	int n, m, k;
	cin >> n >> m >> k;
	
	mat<ll>M(n, vc<ll>(n));
	rep(i, n) M[i][i] = 1;
	
	vc<ll>num(n);
	rep(i, n) cin>>num[i];
	ll rv = modpow(2*m, mod-2);
	rep(i, m){
		int a, b; cin >> a >> b;
		a--; b--;
		M[a][a] -= rv;
		M[b][b] -= rv;
		M[a][b] += rv;
		M[b][a] += rv;
	}
	rep(i, n) rep(j, n) M[i][j] = (M[i][j]%mod+mod)%mod;
	
	mat<ll>ret(n, vc<ll>(n));
	rep(i, n) ret[i][i] = 1;
	while(k){
		if(k&1) ret = ret*M;
		k >>= 1;
		M = M*M;
	}
	mat<ll>ans(n, vc<ll>(1));
	rep(i, n) ans[i][0] = num[i];
	auto result = ret*ans;
	rep(i, n) o(result[i][0]);
}
signed main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
	int t; t = 1; //cin >> t;
	while(t--) solve();
}

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define repa(i,a,n) for (long long i = (a); i < (long long)(n); i++)
#define Rrep(i,n) for (long long i = (long long)(n)-1; i >= 0; i--)
#define Rrepa(i,a,n) for (long long i = (long long)(n)-1; i >= a; i--)
using ll = long long;
class Prints {
    class __Prints {
    public:
        __Prints(const char* sep, const char* term) : sep(sep), term(term) {}
        template <class... Args>
        void operator()(const Args&... args) const { print(args...); }
        template <typename T>
        void pvec(const T& vec, size_t sz) const {
            for (size_t i = 0; i < sz; i++)
                std::cout << vec[i] << (i == sz - 1 ? term : sep);
        }
        template <typename T>
        void pmat(const T& mat, size_t h, size_t w) {
            for (size_t i = 0; i < h; i++)
                for (size_t j = 0; j < w; j++)
                    std::cout << mat[i][j] << (j == w - 1 ? term : sep);
        }

    private:
        const char *sep, *term;
        void print() const { std::cout << term; }
        void print_rest() const { std::cout << term; }
        template <class T, class... Tail>
        void print(const T& head, const Tail&... tail) const { std::cout << head, print_rest(tail...); }
        template <class T, class... Tail>
        void print_rest(const T& head, const Tail&... tail) const { std::cout << sep << head, print_rest(tail...); }
    };

public:
    Prints() {}
    __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); }
};
Prints print;
//一次元配列はprint().pvec(vec,要素数);
//二次元配列はprint().pmat(vec,要素数1,要素数2);
using P = pair<ll,ll>;
const ll INF = 2e18;
ll func(ll N,ll K){
    if (N % K == 0) return 0;
    else return K - (N%K);
}
void dijkstra(vector<vector<tuple<ll,ll,ll>>> &road,ll N,ll M,ll X,ll Y){
    vector<ll> dist(N,INF);
    priority_queue<P, vector<P>, greater<P>> que;
    dist[X] = 0;
    que.push(P(0,X));

    while (!que.empty()){
        P p = que.top();que.pop();
        ll v = p.second;
        if (dist[v] < p.first) continue;
        rep(i,road[v].size()){
            ll val = dist[v] + get<1>(road[v][i]) + func(p.first,get<2>(road[v][i]));
            if (dist[get<0>(road[v][i])] > val){
                dist[get<0>(road[v][i])] = val;
                que.push(P(dist[get<0>(road[v][i])],get<0>(road[v][i])));
            }
        }
    }
    cout << (dist[Y]==INF? -1 : dist[Y]) << endl;
}
int main() {
    ll N,M,X,Y;
    cin >> N >> M >> X >> Y;
    X--;
    Y--;
    vector<vector<tuple<ll,ll,ll>>> d(N);
    rep(i,M){
        ll A,B,T,K;
        cin >> A >> B >> T >> K;
        d[A-1].push_back(make_tuple(B-1,T,K));
        d[B-1].push_back(make_tuple(A-1,T,K));
    }
    dijkstra(d,N,M,X,Y);
}