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?

Let's start by using algebra to solve the problem.

Let x be the number of pencils Simon had in the beginning, and y be the number of pencils Greg had in the beginning.

According to the ratio 7:5, we know that:
- Simon had 7/12 of the total pencils (since the total is 7+5=12)
- Greg had 5/12 of the total pencils

So we can write:
- Simon had (7/12)x pencils
- Greg had (5/12)y pencils

Now let's use the information that Simon gave away 30 pencils and Greg received 30 more pencils. After these changes, they have the same number of pencils.

Simon now has (7/12)x - 30 pencils
Greg now has (5/12)y + 30 pencils

Since they have the same number of pencils, we can set these expressions equal to each other:

(7/12)x - 30 = (5/12)y + 30

Simplifying:
(7/12)x - (5/12)y = 60

Now we have one equation with two variables. But we know that the ratio of their pencils in the beginning was 7:5, which means:

x/y = 7/5

We can use this information to eliminate one variable. Multiplying both sides by y, we get:

x = (7/5)y

Substituting this into our equation above:

(7/12)(7/5)y - (5/12)y = 60

Simplifying:

49y/60 - 5y/12 = 60

Multiplying both sides by 60 to get rid of denominators:

49y - 25y = 3600

24y = 3600

y = 150

So Greg had 150 pencils in the beginning. Using x = (7/5)y, we find that Simon had:

x = (7/5) * 150 = 210

Therefore, Simon had 210 pencils and Greg had 150 pencils in the beginning.

Let's assume that Simon had 7x pencils and Greg had 5x pencils in the beginning.

According to the given information, if Simon gives away 30 pencils, he will have 7x - 30 pencils left.

And if Greg gets 30 more pencils, he will have 5x + 30 pencils.

Now, we can set up an equation based on the information given:

7x - 30 = 5x + 30

Subtracting 5x from both sides, we get:

2x - 30 = 30

Adding 30 to both sides, we get:

2x = 60

Dividing both sides by 2, we get:

x = 30

So, Simon originally had 7 * 30 = 210 pencils.

And Greg originally had 5 * 30 = 150 pencils.

Therefore, Simon had 210 and Greg had 150 pencils in the beginning.