Help!!

Helping my son with homework and I am lost:

find the value of x that makes the mean the given mumber

37, 50, 42, 34, 31 37, 31, x; mean = 38.5

I don't know where to start and where to go next

157, 188, 161, 129, x; mean = 151.8

please help and show me how