Witness Redaction Plan

Time limit1sMemory limit128 MB

Problem

A witness protection program gives crime witnesses new identities to protect them from retaliation by the people they testify against.

Experience shows that many protected witnesses are their own worst enemies: while trying to reach relatives and friends to reassure them that all is well, they give away their new location and identity.

A new pilot allows such contact, but only by email. Program staff first inspect each message and cut out any potentially dangerous sentences, then forward the email from department computers so it cannot be traced back to the witness.

Because the pilot budget was cut, there is not enough money to have people read every message, so an automated solution is needed.

Given a list of sensitive words and a plain-text message, scan the message for any sentence that contains a sensitive word (ignoring letter case). In every such sentence, replace every character (except line terminators) with the character @.

For this problem:

  • A word is a maximal run of consecutive alphanumeric characters. Its boundaries are the start or end of the message and/or any non-alphanumeric character.
  • A sentence is a maximal run of consecutive characters bounded by the start or end of the message, by a paragraph boundary (a line containing zero characters), and/or by one of the punctuation characters ., ?, or !. The punctuation character that ends a sentence belongs to that sentence.

Input

The input contains one or more data sets. Each data set is a word list followed by a message. The end of the input is a line containing only EndOfInput.

A word list contains zero or more words, one per line, left-justified. Each word is at most 40 characters long. The word list ends with a line containing only EndOfList.

The word list is immediately followed by a message. A message contains zero or more lines of text, each at most 80 characters long. The message ends with a line containing only EndOfMsg.

Output

For each data set, print the message exactly as it appears in the input, except that every sentence containing a sensitive word is replaced by @ characters as described above. After each message, print a line containing only four = characters (====).