Solution for the first question