in column E cell E4 put
=LOOKUP(LEFT(B4),{"d","g","s"},{1,3,2})
fill down then sort by col E