Jia Baoyu was the best programmer in his big family—the Family of Jia, which is why he was regarded as the most charming gentleman among girls. Recently he was designing a new microblog to target the requirements of sharing information in his family. In his system, a microblog can be regarded as a document contains no more than 2000 words.
By asked to other member’s in the Family of Jia, he decided to release a function of “subscription” in his microblog. Let’s describe this function more specifically:
A user can submit a query to describe subscription requirement. A query contains a match type, a match distance constraint and a set of not more than 5 English words. After the user submitted the query, he/she will receive all the new microblog that satisfies the query in his/her “Feeds stream”. If a microblog satisfies a query, it should match all the words in the query. And a microblog matches a word X when there is at least a word in microblog that matches the word X. Note that the match constraint is applied independently for each word in the query.
There are three types of word matching: exact match, approximate match under a Hamming distance constraint and approximate match under an edit distance. The definitions of these three matches is are follows:
Exact match: two words are exactly the same;
Approximate match under Hamming distance D constraint:two words with the same length have at most D positions at which corresponding letters are different.
Approximate match under edit distance D constraint:one word can be changed into the other word in at most D single-letter edits, including insertion, deletion and substitution.
For example, Lin Daiyu submitted a query: edit distance match with distance 1, and the word set “flower poem tear”. Then she will receive the microblog “I wrote a pom full of tears after I saw Daiyu buried the flowers”. In this case, “flower” can be matched with “flowers” in 1 edit distance, “tear” can be matched with “tears” and “poem” can be matched with “pom” (obviously it was a typo).
After a user submitted a query, he/she could delete the query in anytime. After that he/she would not receive microblogs that satisfy this query.
Now please help Jia Baoyu to accomplish this function.