Let F= no. of 1st graders and S=no. of 2nd graders.
0.7F+0.3S=0.4(F+S) (total girls).
Divide through by S: 0.7F/S+0.3=0.4(F/S+1)
The ratio of first to second graders is r=F/S so 0.7r+0.3=0.4r+0.4.
0.7r-0.4r=0.4-0.3=0.1, 0.3r=0.1, r=0.1/0.3=1/3 so the ratio is 1:3.