N,M,S =map(int,input().split())
weight_node =list(map(int,input().split()))
child =[[]for i inrange(N)]defdfs(node,weight,path):global out
if weight==S andlen(child[node])==0:print(path)elif weight>S:returnelse:
child_node = child[node]
child_dict =dict()for c in child_node:
child_dict[c]= weight_node[c]
sort_child_node =sorted(child_dict.items(),key=lambda x:x[1],reverse=True)for c in sort_child_node:
dfs(c[0],weight+c[1],path+f" {c[1]}")for m inrange(M):
root,k,*c =map(int,input().split())
child[root]+= c
out =f'{weight_node[0]}'
dfs(0,weight_node[0],out)