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

public class palindromes_akov {
	FastScanner in;
	PrintWriter out;

	boolean[] need;
	int ans = 0;
	
	boolean[][] a;
	
	public void solve() throws IOException {
		char[] c = in.next().toCharArray();
		for (int i = 0; i < c.length; i++) {
			c[i] -= 'a';
		}
		need = new boolean[c.length];
		a = new boolean[26][26];
		int k = in.nextInt();
		for (int i = 0; i < k; i++) {
			int ta = in.next().charAt(0) - 'a', tb = in.next().charAt(0) - 'a';
			a[ta][tb] = true;
		}
		for (int l = 0, r = c.length - 1; l < r; l++, r--) {
			if (c[l] == c[r]) continue;
			if (a[c[l]][c[r]]) {
				need[l] = true;
				ans++;
				continue;
			}
			if (a[c[r]][c[l]]) {
				need[r] = true;
				ans++;
				continue;
			}
			out.println(-1);
			return;
		}
		out.println(ans);
		for (int i = 0; i < c.length; i++) {
			if (need[i]) {
				out.print(i + 1);
			}
		}
	}

	public void run() {
		try {
			in = new FastScanner(new File("palindromes.in"));
			out = new PrintWriter(new File("palindromes.out"));

			solve();

			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		FastScanner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

	}

	public static void main(String[] arg) {
		new palindromes_akov().run();
	}
}