Synonymous Sentences

Given synonymous word pairs and a sentence, generate all possible sentences by replacing synonyms.

Examples
Input: [[["happy","joy"],["sad","sorrow"],["joy","cheerful"]],"I am happy today but was sad yesterday"]
Output: ["I am cheerful today but was sad yesterday","I am cheerful today but was sorrow yesterday","I am happy today but was sad yesterday","I am happy today but was sorrow yesterday","I am joy today but was sad yesterday","I am joy today but was sorrow yesterday"]
Hints

Synonymous Sentences

Given synonymous word pairs and a sentence, generate all possible sentences by replacing synonyms.