Assuming all runners would be earned runs than any inherited runners that score in a way that would be earned are charged to the pitcher that put them there.
So walk the bags full, get yanked and reliever serves up a gopher ball the first guy gets 3 earned runs.