#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
using namespace std;

void radix_sort(vector<string>& v){
	array<vector<string>, 27> buckete;
	const int max_len = max_element(begin(v), end(v), [](const string& a, const string& b){
		return a.size() < b.size(); })->size();
	for(int i = max_len-1; i >= 0; --i){
		for(auto& x : v){
			if(x.size() <= i){
				buckete[0].emplace_back(move(x)); }
			else{
				const int poz = x[i]-'a'+1;
				buckete[poz].emplace_back(move(x)); } }
		auto it = begin(v), it2 = begin(v);
		for(auto& x : buckete){
			it2 = it + x.size();
			move(begin(x), end(x), it);
			x.clear();
			it = it2; } } }

array<int, 26> caracterizeaza(const string& str){
	array<int, 26> rez = {};
	for(const auto x : str){
		++rez[x-'a']; }
	return rez; }

template <typename Input_it1, typename Input_it2, typename Binary_pred>
bool all_of_dublu(Input_it1 st1, Input_it1 dr1, Input_it2 st2, Binary_pred bp){
	for( ; st1 < dr1; ++st1, ++st2){
		if(!bp(*st1, *st2)){
			return false; } }
	return true; }

int main(){
	string mare;
	cin >> mare;

	const auto car_mare = caracterizeaza(mare);

	int n;
	cin >> n;
	vector<string> v(n);
	for(auto& x : v){
		cin >> x; }

	radix_sort(v);

	for(const auto& x : v){
		const auto car_mic = caracterizeaza(x);
		if(all_of_dublu(begin(car_mic), end(car_mic), begin(car_mare), less_equal<int>())){
			cout << x << '\n'; } }
	return 0; }