#include <bits/stdc++.h>
using namespace std;
string s;
int y, n;
string o[105];
bool check(char a, char b)
{ // 大小写不敏感if (a == b || a - 'a' == b - 'A' || a - 'A' == b - 'a'){return true;}return false;
}
int main()
{cin >> s;cin >> y; // 0不敏感1敏感cin >> n;int k = s.size();if (y == 0){for (int i = 0; i < n; i++){cin >> o[i];int len = o[i].size();int kk = 0;for (int j = 0; j < len; j++){if (check(s[kk], o[i][j])){kk++;if (kk == k){cout << o[i] << endl;break;}}else{kk = 0;}}}}else if (y == 1){for (int i = 0; i < n; i++){cin >> o[i];int len = o[i].size();int kk = 0;for (int j = 0; j < len; j++){if (s[kk] == o[i][j]){kk++;if (kk == k){cout << o[i] << endl;break;}}else{kk = 0;}}}}
}