#include <bits/stdc++.h>
#define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define pii pair<int, int>
#define pb push_back
#define fi first
#define se second
using namespace std;
const int M = 250005;
const int N = 505;
const ll INFLL = 1e18+7;
struct edges
{
int u, v, w;
} edge[M];
struct songoku
{
int cost, u, pos;
};
int n, m, q;
int lab[N];
pii trace[N];
vector<songoku> g[N];
ll d[N];
bool mark[M];
ll calc(queue<pii> q)
{
while (!q.empty())
{
int u=q.front().se, kc=q.front().fi; q.pop();
if (kc>=u) continue;
for (songoku x : g[u])
{
if (d[x.u]>d[u]+x.cost)
{
d[x.u]=d[u]+x.cost;
trace[x.u]={u, x.pos};
q.push({d[x.u], x.u});
}
}
}
memset(mark, 0, sizeof(mark));
ll res=0;
for (int i=1; i<=n; i++)
{
int u=i;
while (trace[u].fi!=0)
{
if (mark[trace[u].se]==0) res+=edge[trace[u].se].w;
mark[trace[u].se]=1;
u=trace[u].fi;
}
}
return res;
}
void solve()
{
cin >> n >> m >> q;
for (int i=1; i<=m; i++)
{
int u, v, w;
cin >> u >> v >> w;
edge[i]={u, v, w};
g[u].pb({w, v, i});
g[v].pb({w, u, i});
}
while (q--)
{
int k;
cin >> k;
for (int i=1; i<=n; i++) d[i]=INFLL;
memset(trace, 0, sizeof(trace));
queue<pii> q;
for (int i=1; i<=k; i++)
{
int x;
cin >> x;
q.push({0, x});
d[x]=0;
}
cout << calc(q);
}
}
signed main()
{
io
freopen("giaohang.inp","r",stdin);
freopen("giaohang.out","w",stdout);
solve();
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgaW8gaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbygwKTsgY2luLnRpZSgwKTsgY291dC50aWUoMCk7CiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgcGlpIHBhaXI8aW50LCBpbnQ+CiNkZWZpbmUgcGIgcHVzaF9iYWNrCiNkZWZpbmUgZmkgZmlyc3QKI2RlZmluZSBzZSBzZWNvbmQKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmNvbnN0IGludCBNID0gMjUwMDA1Owpjb25zdCBpbnQgTiA9IDUwNTsKY29uc3QgbGwgSU5GTEwgPSAxZTE4Kzc7CgpzdHJ1Y3QgZWRnZXMKewogICAgaW50IHUsIHYsIHc7Cn0gZWRnZVtNXTsKCnN0cnVjdCBzb25nb2t1CnsKICAgIGludCBjb3N0LCB1LCBwb3M7Cn07CgppbnQgbiwgbSwgcTsKaW50IGxhYltOXTsKcGlpIHRyYWNlW05dOwp2ZWN0b3I8c29uZ29rdT4gZ1tOXTsKbGwgZFtOXTsKYm9vbCBtYXJrW01dOwoKbGwgY2FsYyhxdWV1ZTxwaWk+IHEpCnsKICAgIHdoaWxlICghcS5lbXB0eSgpKQogICAgewogICAgICAgIGludCB1PXEuZnJvbnQoKS5zZSwga2M9cS5mcm9udCgpLmZpOyBxLnBvcCgpOwogICAgICAgIGlmIChrYz49dSkgY29udGludWU7CgogICAgICAgIGZvciAoc29uZ29rdSB4IDogZ1t1XSkKICAgICAgICB7CiAgICAgICAgICAgIGlmIChkW3gudV0+ZFt1XSt4LmNvc3QpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGRbeC51XT1kW3VdK3guY29zdDsKICAgICAgICAgICAgICAgIHRyYWNlW3gudV09e3UsIHgucG9zfTsKICAgICAgICAgICAgICAgIHEucHVzaCh7ZFt4LnVdLCB4LnV9KTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KCiAgICBtZW1zZXQobWFyaywgMCwgc2l6ZW9mKG1hcmspKTsKICAgIGxsIHJlcz0wOwogICAgZm9yIChpbnQgaT0xOyBpPD1uOyBpKyspCiAgICB7CiAgICAgICAgaW50IHU9aTsKICAgICAgICB3aGlsZSAodHJhY2VbdV0uZmkhPTApCiAgICAgICAgewogICAgICAgICAgICBpZiAobWFya1t0cmFjZVt1XS5zZV09PTApIHJlcys9ZWRnZVt0cmFjZVt1XS5zZV0udzsKICAgICAgICAgICAgbWFya1t0cmFjZVt1XS5zZV09MTsKICAgICAgICAgICAgdT10cmFjZVt1XS5maTsKICAgICAgICB9CiAgICB9CgogICAgcmV0dXJuIHJlczsKfQoKdm9pZCBzb2x2ZSgpCnsKICAgIGNpbiA+PiBuID4+IG0gPj4gcTsKICAgIGZvciAoaW50IGk9MTsgaTw9bTsgaSsrKQogICAgewogICAgICAgIGludCB1LCB2LCB3OwogICAgICAgIGNpbiA+PiB1ID4+IHYgPj4gdzsKICAgICAgICBlZGdlW2ldPXt1LCB2LCB3fTsKICAgICAgICBnW3VdLnBiKHt3LCB2LCBpfSk7CiAgICAgICAgZ1t2XS5wYih7dywgdSwgaX0pOwogICAgfQoKICAgIHdoaWxlIChxLS0pCiAgICB7CiAgICAgICAgaW50IGs7CiAgICAgICAgY2luID4+IGs7CgogICAgICAgIGZvciAoaW50IGk9MTsgaTw9bjsgaSsrKSBkW2ldPUlORkxMOwogICAgICAgIG1lbXNldCh0cmFjZSwgMCwgc2l6ZW9mKHRyYWNlKSk7CiAgICAgICAgcXVldWU8cGlpPiBxOwogICAgICAgIGZvciAoaW50IGk9MTsgaTw9azsgaSsrKQogICAgICAgIHsKICAgICAgICAgICAgaW50IHg7CiAgICAgICAgICAgIGNpbiA+PiB4OwogICAgICAgICAgICBxLnB1c2goezAsIHh9KTsKICAgICAgICAgICAgZFt4XT0wOwogICAgICAgIH0KCiAgICAgICAgY291dCA8PCBjYWxjKHEpOwogICAgfQp9CgpzaWduZWQgbWFpbigpCnsKICAgIGlvCiAgICBmcmVvcGVuKCJnaWFvaGFuZy5pbnAiLCJyIixzdGRpbik7CiAgICBmcmVvcGVuKCJnaWFvaGFuZy5vdXQiLCJ3IixzdGRvdXQpOwoKICAgIHNvbHZlKCk7Cn0=