#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;

double EPS=1e-9;
int INF=1000000005;
long long INFF=1000000000000000005ll;
double PI=acos(-1);
int dirx[8]={ -1, 0, 0, 1, -1, -1, 1, 1 };
int diry[8]={ 0, 1, -1, 0, -1, 1, -1, 1 };
ll MOD = 1000000007;

#define DEBUG fprintf(stderr, "====TESTING====\n")
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
#define OUT(x) cout << x << "\n"
#define OUTH(x) cout << x << " "
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define READ(x) for(auto &(z):x) cin >> z;
#define FOR(a, b, c) for (int(a)=(b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a)=(b); (a) <= (c); ++(a))
#define FORD(a, b, c) for (int(a)=(b); (a) >= (c); --(a))
#define FORSQ(a, b, c) for (int(a)=(b); (a) * (a) <= (c); ++(a))
#define FORC(a, b, c) for (char(a)=(b); (a) <= (c); ++(a))
#define EACH(a, b) for (auto&(a) : (b))
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FORN(i, 1, n)
#define MAX(a, b) a=max(a, b)
#define MIN(a, b) a=min(a, b)
#define SQR(x) ((ll)(x) * (x))
#define RESET(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PERMUTE next_permutation
#define TC(t) while (t--)
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define what_is(x) cerr << #x << " is " << x << endl

template<typename T_vector>
void output_vector(const T_vector &v, bool line_break = false, bool add_one = false, int start = -1, int end = -1) {
    if (start < 0) start = 0;
    if (end < 0) end = int(v.size());
    for (int i = start; i < end; i++) {
      cout << v[i] + (add_one ? 1 : 0) << (line_break ? '\n' : i < end - 1 ? ' ' : '\n');
    }
}

const int mxN = 60;
int p[mxN];

void solve() {
    int n; cin >> n;
    // let x be root, k be LCA
    // d(i, j) = d(k, i) ^ d(k, j)
    //         = d(k, i) ^ d(k, j) ^ d(x, k) ^ d(x, k)
    //         = (d(k, i) ^ d(x, k)) ^ (d(k, j) ^ d(x, k))
    //         = d(x, i) ^ d(x, j)
    vector<vector<pll>> g(n), weight(n);
    REP(i, n - 1) {
        ll u, v, w; cin >> u >> v >> w;
        --u, --v;
        g[u].pb({v, w});
        g[v].pb({u, w});
    }
    vl dist(n, -1);
    dist[0] = 0;
    queue<int> q;
    q.push(0);
    while(!q.empty()) {
        int now = q.front(); q.pop();
        EACH(x, g[now]) {
            int next = x.fi;
            ll sum = dist[now] ^ x.se;
            if(dist[next] == -1) {
                dist[next] = sum;
                q.push(next);
            }
        }
    }
    ll ans = 0;
    REP(i, mxN) {
        vi cnt(2);
        REP(j, n) cnt[dist[j] >> i & 1]++;
        ans += (1LL << i) % MOD * cnt[0] % MOD * cnt[1];
        ans %= MOD;
    }
    OUT(ans);
}
 
int main()
{
    FAST_INP;

//    #ifndef ONLINE_JUDGE
//    freopen("input.txt","r", stdin);
//    freopen("output.txt","w", stdout);
//    #endif
 
    // int tc; cin >> tc;
    // TC(tc) solve();
    solve();
    return 0;
}

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <assert.h>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=a;i<b;++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,a) rrepi(i,a,0)
#define rrepi(i,a,b) for(ll i=a-1;i>=b;--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll MOD3 = 1e6;
const ll EPS = 1e-10;
int sgn(const double a){
    return (a < -EPS ? -1 : (a > EPS ? +1 : 0));
}
typedef pair<int,int> pi;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> tri;
typedef pair<double,double> point;
typedef complex<double> Point;
const ll MAX = 1000005;
constexpr ll nx[4] = {-1,0,1,0};
constexpr ll ny[4] = {0,1,0,-1};

ll m; //m次正方行列
vector<ll> matmul(vector<ll> &dp,vector<vector<ll>> &mt){
    vector<ll> ret(m,0);
    rep(i,m) rep(j,m) (ret[i] += mt[i][j]*dp[j]%MOD)%=MOD;
    return ret;
}
vector<vector<ll>> update(vector<vector<ll>> &mt){
    vector<vector<ll>> ret(m,vector<ll>(m,0));
    rep(i,m) rep(j,m) rep(k,m) (ret[i][j] += mt[i][k]*mt[k][j]%MOD)%=MOD;
    return ret;
}
void matpow(vector<ll> &dp,vector<vector<ll>> &mt,ll k){
    m = dp.size();
    while(k){
        if(k&1) dp = matmul(dp,mt);
        mt = update(mt);
        k /= 2; 
    }
}

ll mod_pow(ll n, ll p, ll m){
    ll ret = 1;
    ll mul = n%m;
    while(p){
        if (p&1) ret = ret*mul%m;
        p >>= 1;
        mul = mul*mul%m;
    }
    return ret;
}

class Combination{
    public:
    ll MAX,M;
    vector<ll> fac,finv,inv;
    Combination(ll MAX_,ll MOD_):MAX(MAX_),M(MOD_){
        fac.resize(MAX);
        finv.resize(MAX);
        inv.resize(MAX);
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        rep(i,2,MAX){
            fac[i] = fac[i-1]*i%M;
            inv[i] = M-inv[M%i]*(M/i)%M;
            finv[i] = finv[i-1]*inv[i]%M;
        }
    }

    ll COM(ll n,ll k){
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fac[n]*(finv[k]*finv[n-k]%M)%M;
    }
};

int main(){
    Combination com(100000,MOD);
    ll n,k; //edge
    cin >> m >> n >> k;
    vector<ll> a(m);
    cins(all(a));
    vector<vector<ll>> mat(m,vector<ll>(m,0)),g(m);
    rep(i,m) mat[i][i] = n;
    rep(i,n){
        ll x,y;
        cin >> x >> y;
        x--,y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    rep(i,m){
        ll cnt = 0;
        for (ll v:g[i]){
            mat[i][v]++;
            cnt++;
        }
        mat[i][i] += n-cnt;
    }
    rep(i,m){
        //array_output(all(mat[i]));
    }
    ll re = com.inv[2*n],mul = mod_pow(re,k,MOD);
    matpow(a,mat,k);
    rep(i,m){
        PRINT(a[i]*mul%MOD);
    }
}
