PREFIX ex: <http://example.org/>

SELECT ?s ?o WHERE {
    VALUES ?s { ex:S }
    LATERAL { GRAPH ex:G { FILTER(BOUND(?s)) . VALUES ?o { ex:O } } }
}