def parse_problems(lines):
	""" Given a list of lines, parses them and returns a list of problems. """
	i = 0
	res = []
	while i < len(lines):
		P, G = map(int, lines[i].split())
		grudges = [tuple(map(int, lines[i + n + 1].split())) for n in range(G)]
		i += G + 1
		res.append((P, grudges))
	return res