#include <bits/stdc++.h>
#define fi first
#define se second
#define all(v) v.begin() , v.end()
#define sz(v) int(v.size())
#define unq(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
using namespace std;
typedef long long ll;
typedef pair<int , int> ii;
typedef pair<long long , int> lli;
const int maxN = int(3e5)+7;
int n , m , k , sz[maxN];
vector<int> p[maxN];
bool del[maxN];
ll res_dist = 0;
vector<ii> g[maxN] , res_pair;
void dfs_size(int u , int par){
sz[u] = sz(p[u]);
for (auto e : g[u]){
int v = e.fi;
if (v != par){
dfs_size(v , u);
sz[u] += sz[v];
}
}
}
int dfs_find(int u , int par , int half){
for (auto e : g[u]){
int v = e.fi;
if (v != par && sz[v] > half){
return dfs_find(v , u , half);
}
}
return u;
}
int cnt = 0;
vector<int> ver , tmp[maxN];
void dfs_ins(int u , int par , ll d){
res_dist += 1ll * sz(p[u]) * d;
for (int x : p[u]) tmp[cnt].push_back(x);
for (auto e : g[u]){
int v = e.fi;
int w = e.se;
if (v != par){
dfs_ins(v , u , d + 1ll * w);
}
}
}
void prepare(){
dfs_size(1 , 0);
int u = dfs_find(1 , 0 , k / 2);
for (auto e : g[u]){
int v = e.fi;
int w = e.se;
cnt++;
dfs_ins(v , u , 1ll * w);
}
cnt++;
for (int x : p[u]) tmp[cnt].push_back(x);
priority_queue<ii> pq;
for (int i = 1 ; i <= cnt ; i++){
if (tmp[i].empty() == 0) pq.push({sz(tmp[i]) , i});
}
cout << res_dist << "\n";
while (sz(pq) > 1){
auto X = pq.top(); pq.pop(); int u = X.se;
auto Y = pq.top(); pq.pop(); int v = Y.se;
cout << tmp[u].back() << " " << tmp[v].back() << "\n";
tmp[u].pop_back();
tmp[v].pop_back();
if (tmp[u].empty() == 0) pq.push({sz(tmp[u]) , u});
if (tmp[v].empty() == 0) pq.push({sz(tmp[v]) , v});
}
if (pq.empty() == 0){
int u = pq.top().se;
for (int i = 0 ; i < sz(tmp[u]) ; i += 2){
cout << tmp[u][i] << " " << tmp[u][i + 1] << "\n";
}
}
}
void solve(){
cin >> n >> m >> k;
for (int i = 1 ; i <= m ; i++){
int u , v , w;
cin >> u >> v >> w;
g[u].push_back({v , w});
g[v].push_back({u , w});
}
for (int i = 1 ; i <= k ; i++){
int x; cin >> x;
p[x].push_back(i);
}
prepare();
}
#define name "partner"
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if (fopen(name".INP" , "r")){
freopen(name".INP" , "r" , stdin);
freopen(name".OUT" , "w" , stdout);
}
int t = 1; cin >> t;
solve();
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgZmkgZmlyc3QKI2RlZmluZSBzZSBzZWNvbmQKI2RlZmluZSBhbGwodikgdi5iZWdpbigpICwgdi5lbmQoKQojZGVmaW5lIHN6KHYpIGludCh2LnNpemUoKSkKI2RlZmluZSB1bnEodikgc29ydChhbGwodikpOyB2LnJlc2l6ZSh1bmlxdWUoYWxsKHYpKSAtIHYuYmVnaW4oKSk7CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp0eXBlZGVmIGxvbmcgbG9uZyBsbDsKdHlwZWRlZiBwYWlyPGludCAsIGludD4gaWk7CnR5cGVkZWYgcGFpcjxsb25nIGxvbmcgLCBpbnQ+IGxsaTsKCmNvbnN0IGludCBtYXhOID0gaW50KDNlNSkrNzsKCmludCBuICwgbSAsIGsgLCBzelttYXhOXTsKdmVjdG9yPGludD4gcFttYXhOXTsKYm9vbCBkZWxbbWF4Tl07CmxsIHJlc19kaXN0ID0gMDsKdmVjdG9yPGlpPiBnW21heE5dICwgcmVzX3BhaXI7Cgp2b2lkIGRmc19zaXplKGludCB1ICwgaW50IHBhcil7CiAgICBzelt1XSA9IHN6KHBbdV0pOwogICAgZm9yIChhdXRvIGUgOiBnW3VdKXsKICAgICAgICBpbnQgdiA9IGUuZmk7CiAgICAgICAgaWYgKHYgIT0gcGFyKXsKICAgICAgICAgICAgZGZzX3NpemUodiAsIHUpOwogICAgICAgICAgICBzelt1XSArPSBzelt2XTsKICAgICAgICB9CiAgICB9Cn0KCmludCBkZnNfZmluZChpbnQgdSAsIGludCBwYXIgLCBpbnQgaGFsZil7CiAgICBmb3IgKGF1dG8gZSA6IGdbdV0pewogICAgICAgIGludCB2ID0gZS5maTsKICAgICAgICBpZiAodiAhPSBwYXIgJiYgc3pbdl0gPiBoYWxmKXsKICAgICAgICAgICAgcmV0dXJuIGRmc19maW5kKHYgLCB1ICwgaGFsZik7CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuIHU7Cn0KCmludCBjbnQgPSAwOwp2ZWN0b3I8aW50PiB2ZXIgLCB0bXBbbWF4Tl07Cgp2b2lkIGRmc19pbnMoaW50IHUgLCBpbnQgcGFyICwgbGwgZCl7CiAgICByZXNfZGlzdCArPSAxbGwgKiBzeihwW3VdKSAqIGQ7CiAgICBmb3IgKGludCB4IDogcFt1XSkgdG1wW2NudF0ucHVzaF9iYWNrKHgpOwogICAgZm9yIChhdXRvIGUgOiBnW3VdKXsKICAgICAgICBpbnQgdiA9IGUuZmk7CiAgICAgICAgaW50IHcgPSBlLnNlOwogICAgICAgIGlmICh2ICE9IHBhcil7CiAgICAgICAgICAgIGRmc19pbnModiAsIHUgLCBkICsgMWxsICogdyk7CiAgICAgICAgfQogICAgfQp9Cgp2b2lkIHByZXBhcmUoKXsKICAgIGRmc19zaXplKDEgLCAwKTsKICAgIGludCB1ID0gZGZzX2ZpbmQoMSAsIDAgLCBrIC8gMik7CiAgICBmb3IgKGF1dG8gZSA6IGdbdV0pewogICAgICAgIGludCB2ID0gZS5maTsKICAgICAgICBpbnQgdyA9IGUuc2U7CiAgICAgICAgY250Kys7CiAgICAgICAgZGZzX2lucyh2ICwgdSAsIDFsbCAqIHcpOwogICAgfQogICAgY250Kys7CiAgICBmb3IgKGludCB4IDogcFt1XSkgdG1wW2NudF0ucHVzaF9iYWNrKHgpOwogICAgcHJpb3JpdHlfcXVldWU8aWk+IHBxOwogICAgZm9yIChpbnQgaSA9IDEgOyBpID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ucHVzaF9iYWNrKHt1ICwgd30pOwogICAgfQogICAgZm9yIChpbnQgaSA9IDEgOyBpIDw9IGsgOyBpKyspewogICAgICAgIGludCB4OyBjaW4gPj4geDsKICAgICAgICBwW3hdLnB1c2hfYmFjayhpKTsKICAgIH0KICAgIHByZXBhcmUoKTsKfQoKI2RlZmluZSBuYW1lICJwYXJ0bmVyIgoKaW50IG1haW4oKXsKICAgIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oMCk7IGNpbi50aWUoMCk7IGNvdXQudGllKDApOwogICAgaWYgKGZvcGVuKG5hbWUiLklOUCIgLCAiciIpKXsKICAgICAgICBmcmVvcGVuKG5hbWUiLklOUCIgLCAiciIgLCBzdGRpbik7CiAgICAgICAgZnJlb3BlbihuYW1lIi5PVVQiICwgInciICwgc3Rkb3V0KTsKICAgIH0KICAgIGludCB0ID0gMTsgY2luID4+IHQ7CiAgICBzb2x2ZSgpOwogICAgcmV0dXJuIDA7Cn0KCg==