If A has A pencils and B has B pencils:
After giving 10 pencils to B, A has A-10 pencils and B has B+10 pencils, so B+10=2(A-10).
After giving 10 pencils to A, B has B pencils again and A has A pencils again, so A=B.
B+10=2(A-10) is therefore the same as A+10=2A-20, A=30. So B=A=30.
They each have 30 pencils.