Two friends Tom and Jerry each have a collection of apples. Tom said that if Jerry would give him 8 of his apples they would have an equal number; but, if Tom would give Jerry 8 of his apples, Jerry would have 3 times as many apples as Tom. How many apples does Jerry have?