Suppose I have a list of strings S, each string at most 50 characters long. I'm looking for a data structure and algorithm that can handle the following query efficiently:

Given another list of strings G (a small list of at most 20 strings), I want to find the lexicographically smallest subset of at most 15 strings from S. The result should satisfy the condition that each string in G is a substring of each and every string in the result. i need fast query.

I've searched extensively but couldn't find a satisfactory answer. Most solutions I found address the case with a single string in G, but I need to handle multiple strings as stated above.

Example: S: ["hello my", "yuck ", "mr elan", "now is the", "parag", "hello", "yustuc"] Query1: G: ["el", "m"] Query2: G: ["yu", "uc"] Desired Result1: ["hello my", "mr elan"] Desired Result2: ["yuck", "yustuc"]

If anyone has insights or knows the answer, please share your knowledge.