import java.io.*;
import java.util.HashSet;

public class supersub_ak_wrong {
	
	final static long X = 293017;
	
	void myAssert(boolean cond) {
		if (!cond) {
			throw new AssertionError();
		}
	}
	
	boolean[] letter = new boolean[26];
	
	void validate(char[] s) {
		for (char c : s) {
			myAssert ('a' <= c && c <= 'z');
		}
	}
	
	public void solve(char[] s) {
		for (char c : s) {
			if (!letter[c - 'a']) {
				out.println("NO");
				return;
			}
		}
		int n = s.length;
		long hash;
		for (int i = 0; i < n;) {
			hash = 0;
			int l = i;
			while (i < n && hashes.contains(hash)) {
				hash = hash * X + s[i++];
			}
			i--;
			for (int j = l; j < i; j++) {
				out.print(s[j]);
			}
			if (i == n - 1) {
				out.println(s[n - 1]);
				break;
			}
			out.print('|');
		}
	}
	
	HashSet<Long> hashes;
	void buildSubstrings(char[] t) {
		int n = t.length;
		hashes = new HashSet<Long>();
		hashes.add(0L);
		for (int l = 0; l < n; l++) {
			long hash = 0;
			for (int r = l; r < n; r++) {
				hash = hash * X + t[r];
				hashes.add(hash);
			}
		}
	}
	
	PrintWriter out;
	public void run() throws IOException {
		BufferedReader br = new BufferedReader(new FileReader("supersub.in"));
		out = new PrintWriter("supersub.out");
		char[] t = br.readLine().toCharArray();
		buildSubstrings(t);
		for (char c : t) {
			letter[c - 'a'] = true;
		}
		validate(t);
		int n = Integer.parseInt(br.readLine());
		for (int i = 0; i < n; i++) {
			char[] s = br.readLine().toCharArray();
			validate(s);
			solve(s);
		}
		out.close();
	}
	
	public static void main(String[] args) throws IOException {
		new supersub_ak_wrong().run();
	}
}
