#include <iostream>
#include <cstring>
using namespace std;
const int MAX_SIZE = 10;
bool only(char word[], char x, char y, char z) {
for (int i = 0; i < strlen(word); ++i) {
if (word[i] != x || word[i] != y || word[i] != z) {
return false;
}
}
return true;
}
int main() {
char x, y, z;
int n;
cin >> x >> y >> z;
cin >> n;
for (int i = 1; i <= n; ++i) {
char word[MAX_SIZE + 1];
cin >> word;
if (only(word,x,y,z)) {
cout << word << '\n';
}
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0cmluZz4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmNvbnN0IGludCBNQVhfU0laRSA9IDEwOwoKYm9vbCBvbmx5KGNoYXIgd29yZFtdLCBjaGFyIHgsIGNoYXIgeSwgY2hhciB6KSB7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IHN0cmxlbih3b3JkKTsgKytpKSB7CiAgICAgICAgaWYgKHdvcmRbaV0gIT0geCB8fCB3b3JkW2ldICE9IHkgfHwgd29yZFtpXSAhPSB6KSB7CiAgICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gdHJ1ZTsKfQoKaW50IG1haW4oKSB7CiAgICBjaGFyIHgsIHksIHo7CiAgICBpbnQgbjsKICAgIGNpbiA+PiB4ID4+IHkgPj4gejsKICAgIGNpbiA+PiBuOwogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbjsgKytpKSB7CiAgICAgICAgY2hhciB3b3JkW01BWF9TSVpFICsgMV07CiAgICAgICAgY2luID4+IHdvcmQ7CiAgICAgICAgaWYgKG9ubHkod29yZCx4LHkseikpIHsKICAgICAgICAgICAgY291dCA8PCB3b3JkIDw8ICdcbic7CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuIDA7Cn0=