#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; i--)
#define REP(i, n) for (int i = 0, _n = (n); i < _n; i++)
#define FORE(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define ALL(v) (v).begin(), (v).end()
#define IS_INF(x) (std::isinf(x))
#define IS_NAN(x) (std::isnan(x))
#define fi first
#define se second
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
#define div ___div
#define next ___next
#define prev ___prev
#define left ___left
#define right ___right
#define __builtin_popcount __builtin_popcountll
using namespace std;
template<class X, class Y>
bool minimize(X &x, const Y &y) {
X eps = 1e-9;
if (x > y + eps) {
x = y;
return true;
} else return false;
}
template<class X, class Y>
bool maximize(X &x, const Y &y) {
X eps = 1e-9;
if (x + eps < y) {
x = y;
return true;
} else return false;
}
template<class T>
T Abs(const T &x) {
return (x < 0 ? -x : x);
}
/* Author: Van Hanh Pham */
/** END OF TEMPLATE. DRINK A CUP OF TIGERSUGAR BEFORE READING MY CODE. **/
#define MAX 555
const int INF = (int)1e9 + 7;
const long long LL_INF = (long long)1e18 + 7LL;
int numNode, numEdge, numQuery;
long long dist[MAX][MAX];
int trace[MAX][MAX], cost[MAX][MAX];
int roots[MAX], numRoot;
void loadGraph(void) {
scanf("%d%d%d", &numNode, &numEdge, &numQuery);
memset(cost, 0x3f, sizeof cost);
REP(love, numEdge) {
int u, v, c; scanf("%d%d%d", &u, &v, &c);
minimize(cost[u][v], c);
minimize(cost[v][u], c);
}
}
void floyd(void) {
memset(dist, 0x3f, sizeof dist);
FOR(i, 1, numNode) FOR(j, 1, numNode) if (cost[i][j] < INF) dist[i][j] = cost[i][j];
FOR(i, 1, numNode) dist[i][i] = 0;
FOR(k, 1, numNode) FOR(i, 1, numNode) FOR(j, 1, numNode)
minimize(dist[i][j], dist[i][k] + dist[k][j]);
FOR(from, 1, numNode) FOR(to, 1, numNode) if (from != to) {
trace[from][to] = -1;
FOR(par, 1, numNode) if (par != to && dist[from][par] + cost[par][to] == dist[from][to])
if (trace[from][to] < 0 || cost[trace[from][to]][to] > cost[par][to]) trace[from][to] = par;
}
}
void query(void) {
scanf("%d", &numRoot);
FOR(i, 1, numRoot) scanf("%d", &roots[i]);
long long result = 0;
FOR(node, 1, numNode) {
long long bestDist = LL_INF;
FOR(i, 1, numRoot) minimize(bestDist, dist[roots[i]][node]);
if (bestDist == 0) continue;
int minCost = INF;
FOR(i, 1, numRoot) if (bestDist == dist[roots[i]][node]) {
int par = trace[roots[i]][node];
assert(par > 0);
minimize(minCost, cost[par][node]);
}
result += minCost;
}
printf("%lld ", result);
}
void process(void) {
REP(love, numQuery) query();
printf("\n");
}
int main(void) {
#ifdef ONLINE_JUDGE
freopen("giaohang.inp", "r", stdin);
freopen("giaohang.out", "w", stdout);
#endif // ONLINE_JUDGE
loadGraph();
floyd();
process();
return 0;
}
/*** BUBBLE TEA IS GREAT. MY CODE IS AMAZING :D ***/
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2RlZmluZSBGT1IoaSwgYSwgYikgZm9yIChpbnQgaSA9IChhKSwgX2IgPSAoYik7IGkgPD0gX2I7IGkrKykKI2RlZmluZSBGT1JEKGksIGIsIGEpIGZvciAoaW50IGkgPSAoYiksIF9hID0gKGEpOyBpID49IF9hOyBpLS0pCiNkZWZpbmUgUkVQKGksIG4pIGZvciAoaW50IGkgPSAwLCBfbiA9IChuKTsgaSA8IF9uOyBpKyspCiNkZWZpbmUgRk9SRShpLCB2KSBmb3IgKF9fdHlwZW9mKCh2KS5iZWdpbigpKSBpID0gKHYpLmJlZ2luKCk7IGkgIT0gKHYpLmVuZCgpOyBpKyspCiNkZWZpbmUgQUxMKHYpICh2KS5iZWdpbigpLCAodikuZW5kKCkKI2RlZmluZSBJU19JTkYoeCkgICAoc3RkOjppc2luZih4KSkKI2RlZmluZSBJU19OQU4oeCkgICAoc3RkOjppc25hbih4KSk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