Dasha decide rest solve problem D begin look photo previous competitionslet photo matrix size nm consists lowercase English lettersSome k photo especially interested receive phototemplate paint rectangular area certain color Lets photo special more formally ith special photo receive phototemplate replace character rectangle upper left corner cell coordinate aibi low right corner cell coordinate cidi symbol eiDasha ask find special photo total distance special photo minimum and calculate distancedetermine distance photo sum distance correspond letter the distance letter difference module position alphabet for example distance letter h m equal 8135 letter h 8th alphabet letter m 13th