If a is the first term, ar is the second and ar^2 is the third. The sum is a+ar+ar^2=31. This can also be written a(r^3-1)/(r-1). S6=a(r^6-1)/(r-1)=3906, S6/S3=3906/31=126=(r^3-1)(r^3+1)/(r^3-1)=r^3+1. So r^3=125 and r=5. a(r^3-1)/(r-1)=31=124a/4=31a, so a=1.