import sys
def main():
data = list(map(int, sys.stdin.buffer.read().split()))
it = iter(data)
N = next(it)
M = next(it)
K = next(it)
cost = [0] * N
loc = [0] * N
preconditions = {}
p_v = set()
for i in range(N):
cost[i] = next(it)
loc[i] = next(it)
L = next(it)
for _ in range(L):
s = next(it)
preconditions[(i, s)] = 0
p_v.add(i)
p_v.add(s)
w = [0] * M
flowVerts = [[] for _ in range(M)]
for i in range(M):
w[i] = next(it)
L = next(it)
for _ in range(L):
v = next(it)
if v in p_v:
flowVerts[i] += [v]
pipelines = []
cntFlows = [0] * M
first = [-1] * N
last = [-1] * N
for _ in range(K):
L = next(it)
pipe = [next(it) for _ in range(L)]
pipelines.append(pipe)
walk = []
for f in pipe:
cntFlows[f] += 1
walk.extend(flowVerts[f])
for j, v in enumerate(walk):
last[v] = j
for j in range(len(walk) - 1, -1, -1):
first[walk[j]] = j
for (u, v), cnt in preconditions.items():
if last[u] != -1 and last[v] != -1 and last[u] > first[v]:
preconditions[(u, v)] = cnt + 1
for j, v in enumerate(walk):
last[v] = first[v] = -1
idx = []
cntW = [0] * M
for i, pipe in enumerate(pipelines):
ok = True
for f in pipe:
cntW[f] += 1
if cntFlows[f] - cntW[f] < w[f]:
ok = False
walk = []
for f in pipe:
walk.extend(flowVerts[f])
for j, v in enumerate(walk):
last[v] = j
for j in range(len(walk) - 1, -1, -1):
first[walk[j]] = j
tmp_changes = []
for (u, v), cnt in preconditions.items():
if last[u] != -1 and last[v] != -1 and last[u] > first[v]:
if cnt == 1:
ok = False
if not ok:
idx.append(i)
for f in pipe:
cntW[f] = 0
else:
for f in pipe:
cntFlows[f] -= cntW[f]
cntW[f] = 0
for (u, v) in tmp_changes:
preconditions[(u, v)] -= 1
for j, v in enumerate(walk):
last[v] = first[v] = -1
out = []
out += [str(len(idx))]
if idx:
out += [(" ".join(map(str, idx)))]
else:
out += [""]
out += [str(len(idx))]
for i in idx:
pipe = pipelines[i]
out += [(str(len(pipe)) + " " + ' '.join(map(str, pipe)))]
print("\n".join(out))
if __name__ == "__main__":
main()