What is {position held} of {James G. Blaine} that is {replaced by} is {John W. Foster} ?
For what position did John W. Foster replace James G. Blaine?
What position did James G. Blaine hold when he was replaced by John W. Foster?
SELECT ?d WHERE { resource:James_G._Blaine property:position_held ?s . ?s property:replaced_by resource:John_W._Foster . ?s property:position_held ?d }
select distinct ?obj  where {
?statement <http://www.w3.org/1999/02/22-rdf-syntax-ns#subject> <http://wikidata.dbpedia.org/resource/Q448778> .
?statement <http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate> <http://www.wikidata.org/entity/P39> .
?statement <http://www.w3.org/1999/02/22-rdf-syntax-ns#object> ?obj .
?statement <http://www.wikidata.org/entity/P1366> <http://wikidata.dbpedia.org/resource/Q703642>
} 

SELECT ?obj WHERE { wd:Q448778 p:P39 ?s . ?s ps:P39 ?obj . ?s pq:P1366 wd:Q703642 }