require 'set'

def get_path(g, u, t, reached = Set[u])
	return [t] if u == t

	g[u].each do |v|
		next if reached.include?(v)
		reached << v
		if path = get_path(g, v, t, reached)
			return [u] + path 
		end
	end
	return nil
end

loop do
	params = gets.split.map(&:to_i)
	h, w, c, m, nw, nc, nm = params
	break if h == -1

	node_num = params.inject(:+) * 2 - h + 2

	g = (0..node_num-1).map { Set.new }

	id = 0
	s = id
	heros = (1..h).map { id += 1 }
	warriors_in = (1..w).map { id += 1 }
	warriors_out = (1..w).map { id += 1 }
	dummy_warriors_in = (1..nw).map { id += 1 }
	dummy_warriors_out = (1..nw).map { id += 1 }
	clerics_in = (1..c).map { id += 1 }
	clerics_out = (1..c).map { id += 1 }
	dummy_clerics_in = (1..nc).map { id += 1 }
	dummy_clerics_out = (1..nc).map { id += 1 }
	mages_in = (1..m).map { id += 1 }
	mages_out = (1..m).map { id += 1 }
	dummy_mages_in = (1..nm).map { id += 1 }
	dummy_mages_out = (1..nm).map { id += 1 }
	t = (id += 1)

	heros.each do |j|
		g[s] << j
	end

	warriors_in.each do |j|
		_, *hs = gets.split.map(&:to_i)
		hs.each do |l|
			i = heros[l-1]
			g[i] << j
		end
	end

	warriors_in.zip(warriors_out).each do |i, j|
		g[i] << j
	end

	dummy_warriors_in.each do |j|
		heros.each do |i|
			g[i] << j
		end
	end

	dummy_warriors_out.each do |i|
		clerics_in.each do |j|
			g[i] << j
		end
	end

	dummy_warriors_in.zip(dummy_warriors_out).each do |i, j|
		g[i] << j
	end

	clerics_in.each do |j|
		_, *ws = gets.split.map(&:to_i)
		ws.each do |l|
			i = warriors_out[l-1]
			g[i] << j
		end
	end

	clerics_in.zip(clerics_out).each do |i, j|
		g[i] << j
	end

	dummy_clerics_in.each do |j|
		warriors_out.each do |i|
			g[i] << j
		end
	end

	dummy_clerics_out.each do |i|
		mages_in.each do |j|
			g[i] << j
		end
	end

	dummy_clerics_in.zip(dummy_clerics_out).each do |i, j|
		g[i] << j
	end

	mages_in.each do |j|
		_, *cs = gets.split.map(&:to_i)
		cs.each do |l|
			i = clerics_out[l-1]
			g[i] << j
		end
	end

	mages_out.each do |j|
		g[j] << t
	end

	mages_in.zip(mages_out).each do |i, j|
		g[i] << j
	end

	dummy_mages_in.each do |j|
		clerics_out.each do |i|
			g[i] << j
		end
	end
	
	dummy_mages_out.each do |j|
		g[j] << t
	end

	dummy_mages_in.zip(dummy_mages_out).each do |i, j|
		g[i] << j
	end


	flow = 0
	loop do
		break unless path = get_path(g, s, t)
		flow += 1
		path.reverse.each_cons(2) do |j, i|
			g[i].delete(j)
			g[j] << i
		end
	end
	p flow
end