Simon and Greg shared pencils in the ratio 7:5. If Simon gives away 30 pencils and Greg gets 30 more pencils, they will have the same number of pencils. How many did each of them have in the beginning?