A boy has eight bags, each containing the same amount of cookies. He also has four jars, each with the same amount of cookies. One jar has twice as many cookies as one of the bags. He gives three bags away and then gives away five more cookies. He ends up with 142 cookies. How many cookies were in each bag?

Translate this statement into an equation, using x as the number of cookies in each bag.