#include <bits/stdc++.h>
using namespace std;
// why am I so weak
int n, m, k;
#define MAX_LOG 17
int par[MAX_LOG][100055];
struct edge {int to; int id;};
vector<edge> g[100055];
int depth[100055];
int d[100055];
int dfn[100055], t;
vector<int> vg[100055];
void dfs(int v, int par = -1, int d = 0) {
depth[v] = d;
::par[0][v] = par;
dfn[v] = t++;
for (auto e : g[v]) if (e.to != par) {
dfs(e.to, v, d + 1);
}
}
int lca(int u, int v) {
if (depth[u] > depth[v]) swap(u, v);
for (int i = 0; i < MAX_LOG; i++) {
if (((depth[v] - depth[u]) >> i) & 1) {
v = par[i][v];
}
}
if (u == v) return u;
for (int i = MAX_LOG - 1; i >= 0; i--) {
if (par[i][u] != par[i][v]) {
u = par[i][u];
v = par[i][v];
}
}
return par[0][v];
}
void rdfs(int v, int par, vector<int> &res) {
for (auto e : g[v]) if (e.to != par) {
rdfs(e.to, v, res);
if (d[e.to] >= k) {
res.push_back(e.id);
}
d[v] += d[e.to];
}
}
void gao(int v) {
for (auto u : vg[v]) {
d[u]++;
d[v]--;
gao(u);
}
}
int main() {
scanf("%d %d %d", &n, &m, &k);
for (int i = 0; i + 1 < n; i++) {
int x, y;
scanf("%d %d", &x, &y);
x--, y--;
g[x].push_back((edge){y, i});
g[y].push_back((edge){x, i});
}
dfs(0);
for (int i = 0; i + 1 < MAX_LOG; i++) for (int j = 0; j < n; j++) {
if (~par[i][j]) par[i + 1][j] = par[i][par[i][j]];
else par[i + 1][j] = -1;
}
while (m--) {
int x;
scanf("%d", &x);
vector<int> vec(x);
for (int i = 0; i < x; i++) {
scanf("%d", &vec[i]);
vec[i]--;
vg[vec[i]].clear();
}
sort(vec.begin(), vec.end(), [&] (int u, int v) {
return dfn[u] < dfn[v];
});
vec.erase(unique(vec.begin(), vec.end()), vec.end());
x = (int)vec.size();
for (int i = 0; i + 1 < x; i++) {
vec.push_back(lca(vec[i], vec[i + 1]));
}
sort(vec.begin(), vec.end(), [&] (int u, int v) {
return dfn[u] < dfn[v];
});
vec.erase(unique(vec.begin(), vec.end()), vec.end());
for (auto u : vec) vg[u].clear();
static int sta[100055];
int size = 0;
sta[size++] = vec[0];
for (int i = 1; i < (int)vec.size(); i++) {
int u = vec[i];
int l = lca(u, sta[size - 1]);
if (l != sta[size - 1]) {
while (size >= 2 && depth[sta[size - 2]] >= depth[l]) {
vg[sta[size - 2]].push_back(sta[size - 1]);
size--;
}
if (sta[size - 1] != l) {
vg[l].push_back(sta[--size]);
sta[size++] = l;
}
}
sta[size++] = u;
}
for (int i = 0; i + 1 < size; i++) vg[sta[i]].push_back(sta[i + 1]);
gao(vec[0]);
}
vector<int> res;
rdfs(0, -1, res);
sort(res.begin(), res.end());
printf("%d\n", (int)res.size());
for (int i = 0; i < (int)res.size(); i++) {
if (i) printf(" ");
printf("%d", res[i] + 1);
}
puts("");
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgovLyB3aHkgYW0gSSBzbyB3ZWFrCgppbnQgbiwgbSwgazsKCiNkZWZpbmUgTUFYX0xPRyAxNwoKaW50IHBhcltNQVhfTE9HXVsxMDAwNTVdOwoKc3RydWN0IGVkZ2Uge2ludCB0bzsgaW50IGlkO307Cgp2ZWN0b3I8ZWRnZT4gZ1sxMDAwNTVdOwoKaW50IGRlcHRoWzEwMDA1NV07CmludCBkWzEwMDA1NV07CgppbnQgZGZuWzEwMDA1NV0sIHQ7Cgp2ZWN0b3I8aW50PiB2Z1sxMDAwNTVdOwoKdm9pZCBkZnMoaW50IHYsIGludCBwYXIgPSAtMSwgaW50IGQgPSAwKSB7CglkZXB0aFt2XSA9IGQ7Cgk6OnBhclswXVt2XSA9IHBhcjsKCglkZm5bdl0gPSB0Kys7CgoJZm9yIChhdXRvIGUgOiBnW3ZdKSBpZiAoZS50byAhPSBwYXIpIHsKCQlkZnMoZS50bywgdiwgZCArIDEpOwoJfQp9CmludCBsY2EoaW50IHUsIGludCB2KSB7CglpZiAoZGVwdGh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