#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

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 (a>b) { a=b; return 1; } return 0; }
// dijkstra 蟻本
struct edge {ll to, cost;};
typedef pair<ll, int> P; // firstはsからの最短距離, secondは頂点の番号

const ll INF = 4e18;
int n;
vector<vector<edge>> g;

vector<ll> dijkstra(int n, int s){
	vector<ll> d(n, INF);
	d[s] = 0;

	priority_queue<P,vector<P>,greater<P> > que;
	que.push(P(0, s));

	while(!que.empty()){
		P p = que.top();
		que.pop();

		int v = p.second;
		if(d[v] < p.first) continue; //後から最短パスが見つかった場合、先にqueに入っているものはここではじかれる

		for(int i = 0; i < g[v].size(); i++){
			edge e= g[v][i];
			if(d[e.to] > d[v] + e.cost){
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}

	return d;
}

int nth_bit(int b, int i){
	return (b >> i) & 1;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int m;
	cin >> n >> m;

	g.resize(n, vector<edge>());
	rep(i, m){
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		g[u].push_back({v, 1ll});
		g[v].push_back({u, 1ll});
	}

	int k;
	cin >> k;

	vector<int> t(k);
	rep(i, k){
		cin >> t[i];
		t[i]--;
	}

	vector<vector<ll>> d(k);
	rep(i, k) d[i] = dijkstra(n, t[i]);

	auto dp = vector<vector<ll>>((1 << k), vector<ll>(k, INF));
	rep(i, k) dp[1 << i][i] = 1;

	rep(b, 1 << k) rep(i, k) rep(j, k){
		if(nth_bit(b, i) && !nth_bit(b, j)) {
			chmin(dp[b + (1 << j)][j], dp[b][i] + d[i][t[j]]);
		}
	}

	auto &v = dp[(1 << k) - 1];
	ll ans = *min_element(v.begin(), v.end());
	if(ans == INF){
		cout << -1 << endl;
	}else{
		cout << ans << endl;
	}
}

#include "bits/stdc++.h"

using namespace std;

using ll = int64_t;

#define eb emplace_back

#define F first
#define S second

#define ice(i, a, b) for (int (i) = (a); (i) < (b); ++(i))

const ll MOD = 1e9 + 7;

vector<vector<pair<int, ll>>> adj(200001);
vector<ll> val(200001, 0);

void dfs(int n, int m = -1) {
    for (auto b : adj[n]) {
        if (b.F != m) {
            val[b.F] = val[n] ^ b.S;
            dfs(b.F, n);
        }
    }
}

void solve() {
    int n; cin >> n;
    ice (i, 0, n - 1) {
        int u, v; ll w; cin >> u >> v >> w; --u; --v;
        adj[u].eb(v, w);
        adj[v].eb(u, w);
    }
    dfs(0);
    ll ans = 0;
    ice (i, 0, 60) {
        ll zero = 0, one = 0;
        ice (j, 0, n) {
            val[j] & (1LL << i) ? one++ : zero++;
        }
        ll cnt = (((zero * one) % MOD) * ((1LL << i) % MOD)) % MOD;
        ans = (ans + cnt) % MOD;
    }
    cout << ans;
}

int main() {
    solve();
}