//
// File: bugs.cc
// Author: cteam049
//
// Created on October 27, 2012, 12:03 PM
//
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
//
//
//
bool findBug(int index, int lineLength, char* line, char* replacement, int replLength){
for(int i = index; i - index < replLength ; i++) {
if(i >= lineLength) return false;
if(line[i] != replacement[i - index]) return false;
}
//cout << "bug nalezen" << endl;
return true;
}
int main(int argc, char** argv) {
int lines, len, pos, lineLength = 2000002, tmpLength = 2000002, replLength = 1001;
char line[2000002];
char lineTmp[2000002];
char replacement[1001];
char tmp;
bool found;
while(1){
if(scanf("%d", &lines) != 1) break;
if(scanf(" %s", &replacement) != 1) break;
//precti cislo
//scanf("%d %s", &lines, &replacement);
replLength = strlen(replacement);
getchar();
// cout << "\nlines je " << lines << endl;
// cout << "replacement je " << replacement << endl;
// cout << "delka replacementu je " << replLength << endl;
for(int i = 0; i < lines; i++) {
tmpLength = 0;
lineLength = 0;
//nacti radek
do {
tmp = getchar();
lineTmp[tmpLength] = tmp;
tmpLength++;
} while (tmp != '\n');
// cout << "delka radku je " << tmpLength << endl;
found = true;
//ted je radek nacten
while(found) {
found = false;
lineLength = 0;
for(int j = 0; j < tmpLength; j++) {
//hledame vyskyty bugu
if(findBug(j, tmpLength, lineTmp, replacement, replLength)){
j+= replLength - 1;
found = true;
}
else {
line[lineLength] = lineTmp[j];
lineLength++;
}
//cout << "i je " << i << endl;
}
// cout << "radek po pruchodu: " << endl;
// bugs.cc:100: error: expected unqualified-id before 'return' for(int i = 0; i < lineLength; i++) {
// cout << line[i];
// }
// cout << endl;
for(int j = 0; j < lineLength; j++) {
lineTmp[j] = line[j];
}
tmpLength = lineLength;
}
for(int k = 0; k < lineLength; k++) {
//cout << line[k];
putchar(line[k]);
}
//cout << endl;
}
}
return 0;
}