Let's say I have a list containing different sized sublists of string pairs structured like this
{{{"A", "B"}, {"C", "D"}}, {{"E", "D"}, {"G","B"}}, {{"H", "B"}}, {{"I", "B"}}}
where the first and second sublists each contain two string pairs and the third and fourth sublists each contain 1 string pair.
I want to get rid of every string pair where the second string of the string pair does not appear in each sublist. For example, there exists string pairs in each sublist where the second string of the string pair is "B". Thus, I only want to keep those string pairs. The final list should look like this
{{{"A", "B"}}, {{"G","B"}}, {{"H", "B"}}, {{"I", "B"}}}
Although each of the first two sublists contain a pair of strings where there is a "D" in the second element, these need to be removed since there aren't string pairs containing "D"'s in the second element of the string pairs in the third and fourth sublists.
I would like for this function to work no matter the number of sublists and no matter the number of elements contained in those sublists. I know how to do this if the list was completely flattened, but it is not in this case. There is no need for this to be an efficient process, so anything that can produce these results would be helpful. Any ideas?