Implemented solution to q6
Solution to q7 reusing q3