#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct edge {
int u, v, c;
edge(int u, int v, int c) :
u(u), v(v), c(c) {
}
bool operator<(const edge &e) const {
return c < e.c;
}
};
const int N = 15, oo = 1e9;
int n, m, k, g[N][N], dp[1 << N][N], iv[N], p[N];
vector<edge> e;
int find(int x) {
if (x == p[x])
return x;
return p[x] = find(p[x]);
}
int MST() {
sort(e.begin(), e.end());
for (int i = 0; i < n; ++i)
p[i] = i;
int res = 0;
for (int i = 0; i < m; ++i) {
int u = find(e[i].u);
int v = find(e[i].v);
if (u != v) {
res += e[i].c;
p[u] = v;
}
}
return res;
}
int main(int argc, char **argv) {
int T;
scanf("%d", &T);
while (T-- != 0) {
scanf("%d%d%d", &n, &m, &k);
for (int i = 0; i < n; ++i) {
fill(g[i], g[i] + n, oo);
g[i][i] = 0;
}
e.clear();
int u, v, c;
for (int i = 0; i < m; ++i) {
scanf("%d%d%d", &u, &v, &c);
--u, --v;
g[u][v] = g[v][u] = c;
e.push_back(edge(u, v, c));
}
for (int i = 0; i < k; ++i) {
scanf("%d", &iv[i]);
--iv[i];
}
if (k <= 1) {
puts("0");
continue;
}
if (n == k) {
printf("%d\n", MST());
continue;
}
for (int k = 0; k < n; ++k)
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
for (int i = 0; i < k; ++i)
for (int j = 0; j < n; ++j)
dp[1 << i][j] = g[iv[i]][j];
for (int mask = 1; mask < 1 << k; mask++) {
if (((mask - 1) & mask) == 0)
continue;
for (int i = 0; i < n; ++i) {
dp[mask][i] = oo;
for (int pMask = (mask - 1) & mask; pMask > 0; pMask = (pMask - 1) & mask)
dp[mask][i] = min(dp[mask][i], dp[pMask][i] + dp[mask ^ pMask][i]);
}
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
dp[mask][i] = min(dp[mask][i], dp[mask][j] + g[j][i]);
}
printf("%d\n", dp[(1 << k) - 1][iv[0]]);
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