const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;
void (async function () {
const sentences = (await readline())
.split(/[,.;]/)
.filter((sentence) => sentence !== "");
const words = (await readline()).split(/[,.;]/).filter((word) => word !== "");
console.log(getResult(sentences, words));
})();
const getResult = (sentences, words) => {
const wordSet = new Set(words);
const ans = [];
while (sentences.length > 0) {
const sentence = sentences.shift();
let r = sentence.length;
for (r; r > 0; r--) {
const newWord = sentence.slice(0, r);
if (wordSet.has(newWord)) {
ans.push(newWord);
wordSet.delete(newWord);
if (r < sentence.length) {
sentences.unshift(sentence.slice(r));
}
break;
}
}
if (r == 0) {
ans.push(sentence[0]);
sentences.unshift(sentence.slice(1));
}
}
return ans.join(",");
};