#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 ***/