import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.InputStreamReader;
import java.util.TreeSet;
import java.util.ArrayList;
import java.util.Map;
import java.io.Writer;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Niyaz Nigmatullin
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        FastPrinter out = new FastPrinter(outputStream);
        TaskG solver = new TaskG();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskG {
        public void solve(int testNumber, FastScanner in, FastPrinter out) {
            in.nextInt();
            String s = in.next();
            int m = in.nextInt();
            Map<String, Integer> all = new HashMap<>();
            for (int i = 0; i < m; i++) {
                String p = in.next();
                int c = in.nextInt();
                Integer got = all.get(p);
                if (got == null || got < c) {
                    got = c;
                }
                all.put(p, got);
            }
            final int X = in.nextInt();
            int n = s.length();
            TaskG.MinCostMaxFlowGraph g = new TaskG.MinCostMaxFlowGraph(n + 1);
            for (int i = 0; i < n; i++) {
                g.addEdge(i, i + 1, X, 0);
            }
            TaskG.Edge[] lastEdge = new TaskG.Edge[n + 1];
            long[] d = new long[n + 1];
            long[] h = new long[n + 1];
            long ans = 0;
            for (int i = 0; i < n; i++) {
                for (int j = i + 1; j <= n; j++) {
                    String sub = s.substring(i, j);
                    if (!all.containsKey(sub)) continue;
                    int c = all.get(sub);
                    g.dijkstra(i, lastEdge, d, h);
                    if (d[j] == Long.MAX_VALUE) continue;
                    long pathLen = -c + d[j] - h[i] + h[j];
                    if (pathLen >= 0) {
                        continue;
                    }
                    ans += pathLen;
                    for (int v = j; v != i; v = lastEdge[v].from) {
                        lastEdge[v].flow++;
                    }
                    for (int z = 0; z <= n; z++) {
                        if (d[z] != Long.MAX_VALUE) {
                            h[z] += d[z];
                        }
                    }
                    g.addEdge(j, i, 1, 1, -c);
                }
            }
            out.println(-ans);
        }

        public static class Edge {
            int from;
            int to;
            public int flow;
            int cap;
            long cost;
            TaskG.Edge rev;

            public Edge(int from, int to, int flow, int cap, long cost) {
                this.from = from;
                this.to = to;
                this.flow = flow;
                this.cap = cap;
                this.cost = cost;
            }

            public String toString() {
                return "Edge [from=" + from + ", to=" + to + ", flow=" + flow
                        + ", cap=" + cap + ", cost=" + cost + "]";
            }

        }

        static class MinCostMaxFlowGraph {
            int n;
            ArrayList<TaskG.Edge>[] edges;

            public MinCostMaxFlowGraph(int n) {
                this.n = n;
                edges = new ArrayList[n];
                for (int i = 0; i < edges.length; i++) {
                    edges[i] = new ArrayList<TaskG.Edge>();
                }
            }

            public TaskG.Edge addEdge(int from, int to, int cap, long cost) {
                TaskG.Edge e1 = new TaskG.Edge(from, to, 0, cap, cost);
                TaskG.Edge e2 = new TaskG.Edge(to, from, 0, 0, -cost);
                e1.rev = e2;
                e2.rev = e1;
                edges[from].add(e1);
                edges[to].add(e2);
                return e1;
            }

            public TaskG.Edge addEdge(int from, int to, int cap, int flow, long cost) {
                TaskG.Edge e1 = new TaskG.Edge(from, to, flow, cap, cost);
                TaskG.Edge e2 = new TaskG.Edge(to, from, -flow, 0, -cost);
                e1.rev = e2;
                e2.rev = e1;
                edges[from].add(e1);
                edges[to].add(e2);
                return e1;
            }

            void dijkstra(int source, TaskG.Edge[] lastEdge, final long[] d, long[] h) {
                TreeSet<Integer> ts = new TreeSet<Integer>(new Comparator<Integer>() {
                    public int compare(Integer o1, Integer o2) {
                        if (d[o1] != d[o2]) {
                            return d[o1] < d[o2] ? -1 : 1;
                        }
                        return o1 - o2;
                    }
                });
                Arrays.fill(d, Long.MAX_VALUE);
                d[source] = 0;
                ts.add(source);
                while (!ts.isEmpty()) {
                    int v = ts.pollFirst();
                    for (TaskG.Edge e : edges[v]) {
                        if (e.flow >= e.cap) {
                            continue;
                        }
                        if (d[e.to] == Long.MAX_VALUE
                                || d[e.to] > d[e.from] + e.cost + h[e.from]
                                - h[e.to]) {
                            if (e.cost + h[e.from] - h[e.to] < 0) {
                                throw new AssertionError();
                            }
                            ts.remove(e.to);
                            d[e.to] = d[e.from] + e.cost + h[e.from] - h[e.to];
                            lastEdge[e.to] = e;
                            ts.add(e.to);
                        }
                    }
                }
            }

        }

    }

    static class FastScanner extends BufferedReader {
        public FastScanner(InputStream is) {
            super(new InputStreamReader(is));
        }

        public int read() {
            try {
                int ret = super.read();
//            if (isEOF && ret < 0) {
//                throw new InputMismatchException();
//            }
//            isEOF = ret == -1;
                return ret;
            } catch (IOException e) {
                throw new InputMismatchException();
            }
        }

        public String next() {
            StringBuilder sb = new StringBuilder();
            int c = read();
            while (isWhiteSpace(c)) {
                c = read();
            }
            if (c < 0) {
                return null;
            }
            while (c >= 0 && !isWhiteSpace(c)) {
                sb.appendCodePoint(c);
                c = read();
            }
            return sb.toString();
        }

        static boolean isWhiteSpace(int c) {
            return c >= 0 && c <= 32;
        }

        public int nextInt() {
            int c = read();
            while (isWhiteSpace(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int ret = 0;
            while (c >= 0 && !isWhiteSpace(c)) {
                if (c < '0' || c > '9') {
                    throw new NumberFormatException("digit expected " + (char) c
                            + " found");
                }
                ret = ret * 10 + c - '0';
                c = read();
            }
            return ret * sgn;
        }

        public String readLine() {
            try {
                return super.readLine();
            } catch (IOException e) {
                return null;
            }
        }

    }

    static class FastPrinter extends PrintWriter {
        public FastPrinter(OutputStream out) {
            super(out);
        }

        public FastPrinter(Writer out) {
            super(out);
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Map;
import java.io.Writer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Niyaz Nigmatullin
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        FastPrinter out = new FastPrinter(outputStream);
        TaskG solver = new TaskG();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskG {
        public void solve(int testNumber, FastScanner in, FastPrinter out) {
            in.nextInt();
            String s = in.next();
            int m = in.nextInt();
            Map<String, Integer> all = new HashMap<>();
            for (int i = 0; i < m; i++) {
                String p = in.next();
                int c = in.nextInt();
                Integer got = all.get(p);
                if (got == null || got < c) {
                    got = c;
                }
                all.put(p, got);
            }
            final int X = in.nextInt();
            int n = s.length();
            TaskG.MinCostMaxFlowGraph g = new TaskG.MinCostMaxFlowGraph(n + 1);
            for (int i = 0; i < n; i++) {
                g.addEdge(i, i + 1, X, 0);
            }
            TaskG.Edge[] lastEdge = new TaskG.Edge[n + 1];
            long[] d = new long[n + 1];
            int[] q = new int[n + 2];
            boolean[] inQueue = new boolean[n + 1];
            long ans = 0;
            for (int i = 0; i < n; i++) {
                for (int j = i + 1; j <= n; j++) {
                    String sub = s.substring(i, j);
                    if (!all.containsKey(sub)) continue;
                    int c = all.get(sub);
                    Arrays.fill(d, Long.MAX_VALUE);
                    d[i] = 0;
                    int head = 0;
                    int tail = 0;
                    q[tail++] = i;
                    inQueue[i] = true;
                    while (head != tail) {
                        int v = q[head++];
                        if (head == n + 2) {
                            head = 0;
                        }
                        inQueue[v] = false;
                        for (TaskG.Edge e : g.edges[v]) {
                            if (e.flow < e.cap && d[e.from] != Long.MAX_VALUE && d[e.to] > d[e.from] + e.cost) {
                                d[e.to] = d[e.from] + e.cost;
                                lastEdge[e.to] = e;
                                if (!inQueue[e.to]) {
                                    q[tail++] = e.to;
                                    inQueue[e.to] = true;
                                    if (tail == n + 2) tail = 0;
                                }
                            }
                        }
                    }
                    if (d[j] == Long.MAX_VALUE) continue;
                    long pathLen = -c + d[j];
                    if (pathLen >= 0) {
                        g.addEdge(j, i, 1, -c);
                        continue;
                    }
                    ans += pathLen;
                    for (int v = j; v != i; v = lastEdge[v].from) {
                        lastEdge[v].flow++;
                    }
                    g.addEdge(j, i, 1, 1, -c);
                }
            }
            out.println(-ans);
        }

        public static class Edge {
            int from;
            int to;
            public int flow;
            int cap;
            long cost;
            TaskG.Edge rev;

            public Edge(int from, int to, int flow, int cap, long cost) {
                this.from = from;
                this.to = to;
                this.flow = flow;
                this.cap = cap;
                this.cost = cost;
            }

            public String toString() {
                return "Edge [from=" + from + ", to=" + to + ", flow=" + flow
                        + ", cap=" + cap + ", cost=" + cost + "]";
            }

        }

        static class MinCostMaxFlowGraph {
            int n;
            ArrayList<TaskG.Edge>[] edges;

            public MinCostMaxFlowGraph(int n) {
                this.n = n;
                edges = new ArrayList[n];
                for (int i = 0; i < edges.length; i++) {
                    edges[i] = new ArrayList<TaskG.Edge>();
                }
            }

            public TaskG.Edge addEdge(int from, int to, int cap, long cost) {
                TaskG.Edge e1 = new TaskG.Edge(from, to, 0, cap, cost);
                TaskG.Edge e2 = new TaskG.Edge(to, from, 0, 0, -cost);
                e1.rev = e2;
                e2.rev = e1;
                edges[from].add(e1);
                edges[to].add(e2);
                return e1;
            }

            public TaskG.Edge addEdge(int from, int to, int cap, int flow, long cost) {
                TaskG.Edge e1 = new TaskG.Edge(from, to, flow, cap, cost);
                TaskG.Edge e2 = new TaskG.Edge(to, from, -flow, 0, -cost);
                e1.rev = e2;
                e2.rev = e1;
                edges[from].add(e1);
                edges[to].add(e2);
                return e1;
            }

        }

    }

    static class FastScanner extends BufferedReader {
        public FastScanner(InputStream is) {
            super(new InputStreamReader(is));
        }

        public int read() {
            try {
                int ret = super.read();
//            if (isEOF && ret < 0) {
//                throw new InputMismatchException();
//            }
//            isEOF = ret == -1;
                return ret;
            } catch (IOException e) {
                throw new InputMismatchException();
            }
        }

        public String next() {
            StringBuilder sb = new StringBuilder();
            int c = read();
            while (isWhiteSpace(c)) {
                c = read();
            }
            if (c < 0) {
                return null;
            }
            while (c >= 0 && !isWhiteSpace(c)) {
                sb.appendCodePoint(c);
                c = read();
            }
            return sb.toString();
        }

        static boolean isWhiteSpace(int c) {
            return c >= 0 && c <= 32;
        }

        public int nextInt() {
            int c = read();
            while (isWhiteSpace(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int ret = 0;
            while (c >= 0 && !isWhiteSpace(c)) {
                if (c < '0' || c > '9') {
                    throw new NumberFormatException("digit expected " + (char) c
                            + " found");
                }
                ret = ret * 10 + c - '0';
                c = read();
            }
            return ret * sgn;
        }

        public String readLine() {
            try {
                return super.readLine();
            } catch (IOException e) {
                return null;
            }
        }

    }

    static class FastPrinter extends PrintWriter {
        public FastPrinter(OutputStream out) {
            super(out);
        }

        public FastPrinter(Writer out) {
            super(out);
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.InputStreamReader;
import java.util.TreeSet;
import java.util.ArrayList;
import java.util.Map;
import java.io.Writer;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Niyaz Nigmatullin
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        FastPrinter out = new FastPrinter(outputStream);
        TaskG solver = new TaskG();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskG {
        public void solve(int testNumber, FastScanner in, FastPrinter out) {
            in.nextInt();
            String s = in.next();
            int m = in.nextInt();
            Map<String, Integer> all = new HashMap<>();
            for (int i = 0; i < m; i++) {
                String p = in.next();
                int c = in.nextInt();
                Integer got = all.get(p);
                if (got == null || got < c) {
                    got = c;
                }
                all.put(p, got);
            }
            final int X = in.nextInt();
            int n = s.length();
            TaskG.MinCostMaxFlowGraph g = new TaskG.MinCostMaxFlowGraph(n + 1);
            for (int i = 0; i < n; i++) {
                g.addEdge(i, i + 1, X, 0);
            }
            TaskG.Edge[] lastEdge = new TaskG.Edge[n + 1];
            long[] d = new long[n + 1];
            long[] h = new long[n + 1];
            long ans = 0;
            for (int i = 0; i < n; i++) {
                for (int j = i + 1; j <= n; j++) {
                    String sub = s.substring(i, j);
                    if (!all.containsKey(sub)) continue;
                    int c = all.get(sub);
                    g.dijkstra(i, lastEdge, d, h);
                    if (d[j] == Long.MAX_VALUE) continue;
                    long pathLen = -c + d[j] - h[i] + h[j];
                    if (pathLen >= 0) {
                        continue;
                    }
                    ans += pathLen;
                    for (int v = j; v != i; v = lastEdge[v].from) {
                        lastEdge[v].flow++;
                    }
                    g.addEdge(j, i, 1, 1, -c);
                }
            }
            out.println(-ans);
        }

        public static class Edge {
            int from;
            int to;
            public int flow;
            int cap;
            long cost;
            TaskG.Edge rev;

            public Edge(int from, int to, int flow, int cap, long cost) {
                this.from = from;
                this.to = to;
                this.flow = flow;
                this.cap = cap;
                this.cost = cost;
            }

            public String toString() {
                return "Edge [from=" + from + ", to=" + to + ", flow=" + flow
                        + ", cap=" + cap + ", cost=" + cost + "]";
            }

        }

        static class MinCostMaxFlowGraph {
            int n;
            ArrayList<TaskG.Edge>[] edges;

            public MinCostMaxFlowGraph(int n) {
                this.n = n;
                edges = new ArrayList[n];
                for (int i = 0; i < edges.length; i++) {
                    edges[i] = new ArrayList<TaskG.Edge>();
                }
            }

            public TaskG.Edge addEdge(int from, int to, int cap, long cost) {
                TaskG.Edge e1 = new TaskG.Edge(from, to, 0, cap, cost);
                TaskG.Edge e2 = new TaskG.Edge(to, from, 0, 0, -cost);
                e1.rev = e2;
                e2.rev = e1;
                edges[from].add(e1);
                edges[to].add(e2);
                return e1;
            }

            public TaskG.Edge addEdge(int from, int to, int cap, int flow, long cost) {
                TaskG.Edge e1 = new TaskG.Edge(from, to, flow, cap, cost);
                TaskG.Edge e2 = new TaskG.Edge(to, from, -flow, 0, -cost);
                e1.rev = e2;
                e2.rev = e1;
                edges[from].add(e1);
                edges[to].add(e2);
                return e1;
            }

            void dijkstra(int source, TaskG.Edge[] lastEdge, final long[] d, long[] h) {
                TreeSet<Integer> ts = new TreeSet<Integer>(new Comparator<Integer>() {
                    public int compare(Integer o1, Integer o2) {
                        if (d[o1] != d[o2]) {
                            return d[o1] < d[o2] ? -1 : 1;
                        }
                        return o1 - o2;
                    }
                });
                Arrays.fill(d, Long.MAX_VALUE);
                d[source] = 0;
                ts.add(source);
                while (!ts.isEmpty()) {
                    int v = ts.pollFirst();
                    for (TaskG.Edge e : edges[v]) {
                        if (e.flow >= e.cap) {
                            continue;
                        }
                        if (d[e.to] == Long.MAX_VALUE
                                || d[e.to] > d[e.from] + e.cost + h[e.from]
                                - h[e.to]) {
                            if (e.cost + h[e.from] - h[e.to] < 0) {
                                throw new AssertionError();
                            }
                            ts.remove(e.to);
                            d[e.to] = d[e.from] + e.cost + h[e.from] - h[e.to];
                            lastEdge[e.to] = e;
                            ts.add(e.to);
                        }
                    }
                }
            }

        }

    }

    static class FastScanner extends BufferedReader {
        public FastScanner(InputStream is) {
            super(new InputStreamReader(is));
        }

        public int read() {
            try {
                int ret = super.read();
//            if (isEOF && ret < 0) {
//                throw new InputMismatchException();
//            }
//            isEOF = ret == -1;
                return ret;
            } catch (IOException e) {
                throw new InputMismatchException();
            }
        }

        public String next() {
            StringBuilder sb = new StringBuilder();
            int c = read();
            while (isWhiteSpace(c)) {
                c = read();
            }
            if (c < 0) {
                return null;
            }
            while (c >= 0 && !isWhiteSpace(c)) {
                sb.appendCodePoint(c);
                c = read();
            }
            return sb.toString();
        }

        static boolean isWhiteSpace(int c) {
            return c >= 0 && c <= 32;
        }

        public int nextInt() {
            int c = read();
            while (isWhiteSpace(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int ret = 0;
            while (c >= 0 && !isWhiteSpace(c)) {
                if (c < '0' || c > '9') {
                    throw new NumberFormatException("digit expected " + (char) c
                            + " found");
                }
                ret = ret * 10 + c - '0';
                c = read();
            }
            return ret * sgn;
        }

        public String readLine() {
            try {
                return super.readLine();
            } catch (IOException e) {
                return null;
            }
        }

    }

    static class FastPrinter extends PrintWriter {
        public FastPrinter(OutputStream out) {
            super(out);
        }

        public FastPrinter(Writer out) {
            super(out);
        }

    }
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Deque;
import java.util.LinkedList;
import java.util.StringTokenizer;

import javax.swing.text.TabableView;

public class G {

	static StringTokenizer st;
	static BufferedReader br;
	static PrintWriter pw;
	static int[][]a, c;
	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		int n = nextInt();
		String s = next();
		int m = nextInt();
		a = new int[n+2][n+2];
		c = new int[n+2][n+2];
		for (int i = 0; i < m; i++) {
			String t = next();
			int cost = nextInt();
			for (int j = 0; j <= s.length()-t.length(); j++) {
				if (s.substring(j, j+t.length()).equals(t)) {
					addAge(j+1, j+t.length()+1, 1, -cost);
				}
			}
		}
		int x = nextInt();
		int source = 0, target = n+1;
		int INF = (int) 1e4;
		addAge(source, 1, x, 0);
		for (int i = 1; i <= n; i++) {
			addAge(i, i+1, INF, 0);
		}
		System.out.println(-minCostFlow(source, target));
		pw.close();
	}
	private static int minCostFlow(int source, int target) {
		int res = 0;
		int[]d = new int[target+1];
		int INF = (int) 1e9;
		Deque<Integer> dq = new LinkedList<>();
		int[]id = new int[target+1];
		int[]p = new int[target+1];
		int[][]f = new int[target+1][target+1];
		while (true) {
			dq.add(source);
			Arrays.fill(id, 2);
			Arrays.fill(p, -1);
			id[source] = 1;
			Arrays.fill(d, INF);
			d[source] = 0;
			while (!dq.isEmpty()) {
				int v = dq.pollFirst();
				id[v] = 0;
				for (int i = 0; i <= target; i++) {
					if (d[v] + c[v][i] < d[i] && a[v][i]-f[v][i] > 0) {
						d[i] = d[v] + c[v][i];
						p[i] = v;
						if (id[i]==0)
							dq.addFirst(i);
						else if (id[i]==2)
							dq.addLast(i);
						id[i] = 1;
					}
				}
			}
			if (d[target]==INF)
				break;
			int cur = target;
			int addFlow = INF;
			while (true) {
				int prev = p[cur];
				addFlow = Math.min(addFlow, a[prev][cur]-f[prev][cur]);
				if (prev==source)
					break;
				cur = prev;
			}
			cur = target;
			int cost = 0;
			while (true) {
				int prev = p[cur];
				f[prev][cur] += addFlow;
				f[cur][prev] -= addFlow;
				cost += addFlow * c[prev][cur];
				if (prev==source)
					break;
				cur = prev;
			}
			res += cost;
		}
		return res;
	}
	private static void addAge(int i, int j, int flow, int cost) {
		a[i][j] += flow;
		c[i][j] = cost;
		c[j][i] = -cost;
	}
	private static int nextInt() throws IOException {
		return Integer.parseInt(next());
	}
	private static long nextLong() throws IOException {
		return Long.parseLong(next());
	}
	private static double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}
	private static String next() throws IOException {
		while (st==null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Deque;
import java.util.LinkedList;
import java.util.StringTokenizer;

public class G {

	static StringTokenizer st;
	static BufferedReader br;
	static PrintWriter pw;
	static class Age {
		int id, c, u, f, id_to;
		public Age(int to, int c, int u, int f, int id_to) {
			this.id = to;
			this.c = c;
			this.u = u;
			this.f = f;
			this.id_to = id_to;
		}
	}
	static ArrayList<Age>[]ages;
	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		int n = nextInt();
		String s = next();
		int source = 0, target = n+1;
		int m = nextInt();
		ages = new ArrayList[target+1];
		for (int i = 0; i <= target; i++) {
			ages[i] = new ArrayList<Age>();
		}
		for (int i = 0; i < m; i++) {
			String t = next();
			int cost = nextInt();
			for (int j = 0; j <= s.length()-t.length(); j++) {
				if (s.substring(j, j+t.length()).equals(t)) {
					addAge(j+1, j+t.length()+1, 1, -cost);
				}
			}
		}
		int x = nextInt();
		int INF = (int) 1e4;
		addAge(source, 1, x, 0);
		for (int i = 1; i <= n; i++) {
			addAge(i, i+1, INF, 0);
		}
		System.out.println(-minCostFlow(source, target));
		pw.close();
	}
	private static int minCostFlow(int source, int target) {
		int res = 0;
		int[]d = new int[target+1];
		int INF = (int) 1e9;
		Deque<Integer> dq = new LinkedList<>();
		int[]id = new int[target+1];
		int[]p = new int[target+1];
		int[]p_age = new int[target+1];
		while (true) {
			dq.add(source);
			Arrays.fill(id, 2);
			Arrays.fill(p, -1);
			id[source] = 1;
			Arrays.fill(d, INF);
			d[source] = 0;
			while (!dq.isEmpty()) {
				int v = dq.pollFirst();
				id[v] = 0;
				int id_age = 0;
				for (Age to : ages[v]) {
					if (d[v] + to.c < d[to.id] && to.u-to.f > 0) {
						d[to.id] = d[v] + to.c;
						p[to.id] = v;
						p_age[to.id] = id_age;
						if (id[to.id]==0)
							dq.addFirst(to.id);
						else if (id[to.id]==2)
							dq.addLast(to.id);
						id[to.id] = 1;
					}
					id_age++;
				}
			}
			if (d[target]==INF)
				break;
			int cur = target;
			int addFlow = INF;
			while (true) {
				int prev = p[cur];
				int id_age = p_age[cur];
				addFlow = Math.min(addFlow, ages[prev].get(id_age).u-ages[prev].get(id_age).f);
				if (prev==source)
					break;
				cur = prev;
			}
			cur = target;
			int cost = 0;
			while (true) {
				int prev = p[cur];
				int id_age = p_age[cur];
				Age age = ages[prev].get(id_age);
				age.f += addFlow;
				cost += addFlow * age.c;
				ages[prev].set(id_age, age);
				id_age = age.id_to;
				age = ages[cur].get(id_age);
				age.f -= addFlow;
				ages[cur].set(id_age, age);
				if (prev==source)
					break;
				cur = prev;
			}
			res += cost;
		}
		return res;
	}
	private static void addAge(int i, int j, int flow, int cost) {
		ages[i].add(new Age(j, cost, flow, 0, ages[j].size()));
		ages[j].add(new Age(i, -cost, 0, 0, ages[i].size()-1));
	}
	private static int nextInt() throws IOException {
		return Integer.parseInt(next());
	}
	private static long nextLong() throws IOException {
		return Long.parseLong(next());
	}
	private static double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}
	private static String next() throws IOException {
		while (st==null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Deque;
import java.util.LinkedList;
import java.util.StringTokenizer;

import javax.swing.text.TabableView;

public class G {

	static StringTokenizer st;
	static BufferedReader br;
	static PrintWriter pw;
	static class Age {
		int id, c, u, f, id_to;
		public Age(int to, int c, int u, int f, int id_to) {
			this.id = to;
			this.c = c;
			this.u = u;
			this.f = f;
			this.id_to = id_to;
		}
	}
	static ArrayList<Age>[]ages;
	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		int n = nextInt();
		String s = next();
		int source = 0, target = n+1;
		int m = nextInt();
		ages = new ArrayList[target+1];
		for (int i = 0; i <= target; i++) {
			ages[i] = new ArrayList<Age>();
		}
		for (int i = 0; i < m; i++) {
			String t = next();
			int cost = nextInt();
			for (int j = 0; j <= s.length()-t.length(); j++) {
				if (s.substring(j, j+t.length()).equals(t)) {
					addAge(j+1, j+t.length()+1, 1, -cost);
				}
			}
		}
		int x = nextInt();
		int INF = (int) 1e4;
		addAge(source, 1, x, 0);
		for (int i = 1; i <= n; i++) {
			addAge(i, i+1, INF, 0);
		}
		System.out.println(-minCostFlow(source, target));
		pw.close();
	}
	private static int minCostFlow(int source, int target) {
		int res = 0;
		int[]d = new int[target+1];
		int INF = (int) 1e9;
		Deque<Integer> dq = new LinkedList<>();
		int[]id = new int[target+1];
		int[]p = new int[target+1];
		int[]p_age = new int[target+1];
		while (true) {
			dq.add(source);
			Arrays.fill(id, 2);
			Arrays.fill(p, -1);
			id[source] = 1;
			Arrays.fill(d, INF);
			d[source] = 0;
			while (!dq.isEmpty()) {
				int v = dq.pollFirst();
				id[v] = 0;
				int id_age = 0;
				for (Age to : ages[v]) {
					if (d[v] + to.c < d[to.id] && to.u-to.f > 0) {
						d[to.id] = d[v] + to.c;
						p[to.id] = v;
						p_age[to.id] = id_age;
						if (id[to.id]==0)
							dq.addFirst(to.id);
						else if (id[to.id]==2)
							dq.addLast(to.id);
						id[to.id] = 1;
					}
					id_age++;
				}
			}
			if (d[target]==INF)
				break;
			int cur = target;
			int addFlow = INF;
			while (true) {
				int prev = p[cur];
				int id_age = p_age[cur];
				addFlow = Math.min(addFlow, ages[prev].get(id_age).u-ages[prev].get(id_age).f);
				if (prev==source)
					break;
				cur = prev;
			}
			cur = target;
			int cost = 0;
			while (true) {
				int prev = p[cur];
				int id_age = p_age[cur];
				Age age = ages[prev].get(id_age);
				age.f += addFlow;
				cost += addFlow * age.c;
				ages[prev].set(id_age, age);
				id_age = age.id_to;
				age = ages[cur].get(id_age);
				age.f -= addFlow;
				ages[cur].set(id_age, age);
				if (prev==source)
					break;
				cur = prev;
			}
			res += cost;
		}
		return res;
	}
	private static void addAge(int i, int j, int flow, int cost) {
		ages[i].add(new Age(j, cost, flow, 0, ages[j].size()));
		ages[j].add(new Age(i, -cost, 0, 0, ages[i].size()));
	}
	private static int nextInt() throws IOException {
		return Integer.parseInt(next());
	}
	private static long nextLong() throws IOException {
		return Long.parseLong(next());
	}
	private static double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}
	private static String next() throws IOException {
		while (st==null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public class G {

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok;

    void init() {
        try {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        } catch (Exception e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }
    }

    String readString() {
        try {
            while (tok == null || !tok.hasMoreTokens()) {
                tok = new StringTokenizer(in.readLine());
            }
            return tok.nextToken();
        } catch (Exception e) {
            return null;
        }
    }

    int readInt() {
        return Integer.parseInt(readString());
    }

    long readLong() {
        return Long.parseLong(readString());
    }

    int[] readIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = readInt();
        }
        return a;
    }

    public static void main(String[] args) {
        new G().run();
    }

    void run() {
        try {
            long tStart = System.currentTimeMillis();
            init();
            solve();
            in.close();
            out.close();
            long tEnd = System.currentTimeMillis();

            System.err.println(tEnd - tStart);
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    boolean equal(char[] a, char[] b, int fromA, int fromB) {
        int len1 = a.length - fromA;
        int len2 = b.length - fromB;
        if (len2 > len1) return false;
        for (int i = 0; i < len2; i++) {
            if (a[fromA + i] != b[fromB + i]) return false;
        }
        return true;
    }

    void solve() {
        int n = readInt();
        char[] a = readString().toCharArray();
        Set<Integer>[] banned = new Set[n];
        for (int i = 0; i < n; i++) {
            banned[i] = new HashSet<>();
        }
        int m = readInt();

        char[][] names = new char[m][];
        int[] p = new int[m];
        for (int i = 0; i < m; i++) {
            names[i] = readString().toCharArray();
            p[i] = readInt();
        }
        int x = readInt();

        boolean[][] eq = new boolean[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                eq[i][j] = equal(a, names[j], i, 0);
            }
        }

        int ans = 0;

        for (int times = 0; times < x; times++) {
            int[] dp = new int[n + 1];
            int[] parent = new int[n + 1];
            Arrays.fill(parent, -1);
            for (int from = 0; from < n; from++) {
                for (int word = 0; word < m; word++) {
                    if (banned[from].contains(word)) continue;
                    if (!eq[from][word]) continue;

                    if (dp[from + names[word].length] < dp[from] + p[word]) {
                        dp[from + names[word].length] = dp[from] + p[word];
                        parent[from + names[word].length] = word;
                    }
                }
            }

            int max = 0;
            int maxI = 0;
            for (int i = 0; i <= n; i++) {
                if (dp[i] > max) {
                    max = dp[i];
                    maxI = i;
                }
            }
            if (max == 0) continue;
            ans += max;

            while (true) {
                if (parent[maxI] == -1) break;
                banned[maxI - names[parent[maxI]].length].add(parent[maxI]);
                maxI = maxI - names[parent[maxI]].length;
            }
        }
        out.println(ans);

    }
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class G {

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok;

    void init() {
        try {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        } catch (Exception e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }
    }

    String readString() {
        try {
            while (tok == null || !tok.hasMoreTokens()) {
                tok = new StringTokenizer(in.readLine());
            }
            return tok.nextToken();
        } catch (Exception e) {
            return null;
        }
    }

    int readInt() {
        return Integer.parseInt(readString());
    }

    long readLong() {
        return Long.parseLong(readString());
    }

    int[] readIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = readInt();
        }
        return a;
    }

    public static void main(String[] args) {
        new G().run();
    }

    void run() {
        try {
            long tStart = System.currentTimeMillis();
            init();
            solve();
            in.close();
            out.close();
            long tEnd = System.currentTimeMillis();

            System.err.println(tEnd - tStart);
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    boolean equal(char[] a, char[] b, int fromA, int fromB) {
        int len1 = a.length - fromA;
        int len2 = b.length - fromB;
        if (len2 > len1) return false;
        for (int i = 0; i < len2; i++) {
            if (a[fromA + i] != b[fromB + i]) return false;
        }
        return true;
    }

    void solve() {
        int n = readInt();
        char[] a = readString().toCharArray();
        Set<Integer>[] banned = new Set[n];
        for (int i = 0; i < n; i++) {
            banned[i] = new HashSet<>();
        }
        int m = readInt();
        char[][] names = new char[m][];
        int[] p = new int[m];
        for (int i = 0; i < m; i++) {
            names[i] = readString().toCharArray();
            p[i] = readInt();
        }
        int x = readInt();

        boolean[][] eq = new boolean[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                eq[i][j] = equal(a, names[j], i, 0);
            }
        }

        int ans = 0;

        for (int times = 0; times < x; times++) {
            int[] dp = new int[n + 1];
            int[] parent = new int[n + 1];
            int[] parentI = new int[n + 1];
            Arrays.fill(parent, -1);
            for (int from = 0; from < n; from++) {
                if (from > 0) {
                    if (dp[from - 1] > dp[from]) {
                        dp[from] = dp[from - 1];
                        parent[from] = parent[from - 1];
                        parentI[from] = parentI[from - 1];
                    }
                }

                for (int word = 0; word < m; word++) {
                    if (banned[from].contains(word)) continue;
                    if (!eq[from][word]) continue;

                    if (dp[from + names[word].length] < dp[from] + p[word]) {
                        dp[from + names[word].length] = dp[from] + p[word];
                        parent[from + names[word].length] = word;
                        parentI[from + names[word].length] = from;
                    }
                }
            }

            int max = 0;
            int maxI = 0;
            for (int i = 0; i <= n; i++) {
                if (dp[i] > max) {
                    max = dp[i];
                    maxI = i;
                }
            }
            if (max == 0) continue;
            ans += max;

            while (true) {
                if (parent[maxI] == -1) break;
                banned[parentI[maxI]].add(parent[maxI]);
                maxI = parentI[maxI];
            }
        }
        out.println(ans);

    }
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class G {

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok;

    void init() {
        try {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        } catch (Exception e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }
    }

    String readString() {
        try {
            while (tok == null || !tok.hasMoreTokens()) {
                tok = new StringTokenizer(in.readLine());
            }
            return tok.nextToken();
        } catch (Exception e) {
            return null;
        }
    }

    int readInt() {
        return Integer.parseInt(readString());
    }

    long readLong() {
        return Long.parseLong(readString());
    }

    int[] readIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = readInt();
        }
        return a;
    }

    public static void main(String[] args) {
        new G().run();
    }

    void run() {
        try {
            long tStart = System.currentTimeMillis();
            init();
            solve();
            in.close();
            out.close();
            long tEnd = System.currentTimeMillis();

            System.err.println(tEnd - tStart);
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    boolean equal(char[] a, char[] b, int fromA, int fromB) {
        int len1 = a.length - fromA;
        int len2 = b.length - fromB;
        if (len2 > len1) return false;
        for (int i = 0; i < len2; i++) {
            if (a[fromA + i] != b[fromB + i]) return false;
        }
        return true;
    }

    class Edge {
        int from;
        int to;
        int cap;
        int cost;
        int flow;
        Edge opposite;

        public Edge(int from, int to, int cap, int cost) {
            this.from = from;
            this.to = to;
            this.cap = cap;
            this.cost = cost;
        }
    }

    Edge[] edges = new Edge[20000];
    int index = 0;

    void addEdge(int from, int to, int cap, int cost) {
        Edge a = new Edge(from, to, cap, cost);
        Edge b = new Edge(to, from, 0, -cost);
        a.opposite = b;
        b.opposite = a;
        edges[index++] = a;
        edges[index++] = b;
    }

    void solve() {
        int n = readInt();
        char[] a = readString().toCharArray();
        int m = readInt();
        char[][] names = new char[m][];
        int[] p = new int[m];
        for (int i = 0; i < m; i++) {
            names[i] = readString().toCharArray();
            p[i] = readInt();
        }
        int x = readInt();

        int ans = 0;
        int SRC = 0;
        int SINK = n + 1;

        int INF = 1000;

        addEdge(SRC, 1, x, 0);
        addEdge(1 + n - 1, SINK, x, 0);

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (equal(a, names[j], i, 0)) {
                    addEdge(1 + i, 1 + i + names[j].length, 1, -p[j]);
                }
            }
        }
        for (int i = 0; i < n - 1; i++) {
            addEdge(1 + i, 1 + i + 1, INF, 0);
        }

        int flowVertexCount = n + 2;

        int[] dist = new int[flowVertexCount];
        int[] parent = new int[flowVertexCount];

        while (x-- > 0) {
            Arrays.fill(dist, Integer.MAX_VALUE);
            Arrays.fill(parent, -1);
            dist[SRC] = 0;
            while (true) {
                boolean found = false;
                for (int i = 0; i < index; i++) {
                    Edge e = edges[i];
                    if (dist[e.from] == Integer.MAX_VALUE) continue;
                    if (e.flow >= e.cap) continue;
                    if (dist[e.from] + e.cost < dist[e.to]) {
                        found = true;
                        dist[e.to] = dist[e.from] + e.cost;
                        parent[e.to] = i;
                    }
                }
                if (!found) break;
            }

            if (dist[SINK] >= 0) break;
            ans -= dist[SINK];

            int cur = SINK;
            while (parent[cur] != -1) {
                Edge e = edges[parent[cur]];
                e.flow++;
                e.opposite.flow--;
                cur = e.from;
            }
        }
        out.println(ans);

    }
}


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

public class test {

	public static void main(String[] args) {
		int test = fs.nextInt();
//		int test = 1;
		for (int cases = 0; cases < test; cases++) {
			String s = fs.next();
			char ar[] = s.toCharArray();
			int n = ar.length;
			Set<Character> set = new HashSet<Character>();
			for (int i = 0; i < ar.length; i++) {
				set.add(ar[i]);
			}
			Iterator<Character> iterator = set.iterator();
			String ans = "";
			while (iterator.hasNext()) {
				Character character = iterator.next();
				boolean rs = true;
				for (int i = 0; i < n ;) {
					int c = 1;
					if (ar[i] == character) {
						int j = i + 1;
						for (; j < n; j++) {
							if (ar[j] == ar[i]) {
								++c;
							} else {
								break;
							}
						}
						i = j;
					}
					else
					{
						++i;
						continue;
					}
					if (c % 2 != 0) {
						rs = true;
						break;
					} else if (c % 2 == 0) {
						rs = false;
					}
				}
				if (rs) {
					ans += character;
				}
			}
			op.print(ans + "\n");
			op.flush();
		}
	}

	static int countDifferentBits(int a, int b) {
		int count = 0;
		for (int i = 0; i < 32; i++) {
			if (((a >> i) & 1) != ((b >> i) & 1)) {
				++count;
			}
		}
		return count;
	}

	static int gcd(int a, int b) {
		if (b == 0)
			return a;
		return gcd(b, a % b);
	}

	static void sortMyMapusingValues(HashMap<String, Integer> hm) {

		List<Map.Entry<String, Integer>> capitalList = new LinkedList<>(hm.entrySet());

		Collections.sort(capitalList, new Comparator<Map.Entry<String, Integer>>() {
			public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
				return (o1.getValue()).compareTo(o2.getValue());
			}
		});
		HashMap<String, Integer> result = new HashMap<>();
		for (Map.Entry<String, Integer> entry : capitalList) {
			result.put(entry.getKey(), entry.getValue());
		}
	}

	static boolean ispowerof2(long num) {
		if ((num & (num - 1)) == 0)
			return true;
		return false;
	}

	static void primeFactors(int n) {
		while (n % 2 == 0) {
			System.out.print(2 + " ");
			n /= 2;
		}
		for (int i = 3; i <= Math.sqrt(n); i += 2) {
			while (n % i == 0) {
				System.out.print(i + " ");
				n /= i;
			}
		}
		if (n > 2)
			System.out.print(n);
	}

	static boolean isPrime(int n) {
		// Corner cases
		if (n <= 1)
			return false;
		if (n <= 3)
			return true;
		if (n % 2 == 0 || n % 3 == 0)
			return false;

		for (int i = 5; i * i <= n; i = i + 6)
			if (n % i == 0 || n % (i + 2) == 0)
				return false;

		return true;
	}

	static class Graph {
		HashMap<Integer, LinkedList<Integer>> hm = new HashMap<Integer, LinkedList<Integer>>();

		private void addVertex(int vertex) {
			hm.put(vertex, new LinkedList<>());
		}

		private void addEdge(int source, int dest, boolean bi) {
			if (!hm.containsKey(source))
				addVertex(source);
			if (!hm.containsKey(dest))
				addVertex(dest);
			hm.get(source).add(dest);
			if (bi) {
				hm.get(dest).add(source);
			}
		}

		private boolean uniCycle(int i, HashSet<Integer> visited, int parent) {
			visited.add(i);
			LinkedList<Integer> list = hm.get(i);
			Iterator<Integer> it = list.iterator();
			while (it.hasNext()) {
				Integer integer = (Integer) it.next();
				if (!visited.contains(integer)) {
					if (uniCycle(integer, visited, i))
						return true;
				} else if (integer != parent) {
					return true;
				}
			}
			return false;
		}

		private boolean uniCyclic() {
			HashSet<Integer> visited = new HashSet<Integer>();
			Set<Integer> set = hm.keySet();
			for (Integer integer : set) {
				if (!visited.contains(integer)) {
					if (uniCycle(integer, visited, -1)) {
						return true;
					}
				}
			}
			return false;
		}

		private boolean isbiCycle(int i, HashSet<Integer> visited, HashSet<Integer> countered) {
			if (countered.contains(i))
				return true;
			if (visited.contains(i))
				return false;
			visited.add(i);
			countered.add(i);
			LinkedList<Integer> list = hm.get(i);
			Iterator<Integer> it = list.iterator();
			while (it.hasNext()) {
				Integer integer = (Integer) it.next();
				if (isbiCycle(integer, visited, countered)) {
					return true;
				}
			}
			countered.remove(i);
			return false;
		}

		private boolean isbiCyclic() {
			HashSet<Integer> visited = new HashSet<Integer>();
			HashSet<Integer> countered = new HashSet<Integer>();
			Set<Integer> set = hm.keySet();
			for (Integer integer : set) {
				if (isbiCycle(integer, visited, countered)) {
					return true;
				}
			}
			return false;
		}
	}

	static class Node {
		Node left, right;
		int data;

		public Node(int data) {
			this.data = data;
		}

		public void insert(int val) {
			if (val <= data) {
				if (left == null) {
					left = new Node(val);
				} else {
					left.insert(val);
				}
			} else {
				if (right == null) {
					right = new Node(val);
				} else {
					right.insert(val);
				}
			}
		}

		public boolean contains(int val) {
			if (data == val) {
				return true;
			} else if (val < data) {
				if (left == null) {
					return false;
				} else {
					return left.contains(val);
				}
			} else {
				if (right == null) {
					return false;
				} else {
					return right.contains(val);
				}
			}
		}

		public void inorder() {
			if (left != null) {
				left.inorder();
			}
			System.out.print(data + " ");
			if (right != null) {
				right.inorder();
			}
		}

		public int maxDepth() {
			if (left == null)
				return 0;
			if (right == null)
				return 0;
			else {
				int ll = left.maxDepth();
				int rr = right.maxDepth();
				if (ll > rr)
					return (ll + 1);
				else
					return (rr + 1);
			}
		}

		public int countNodes() {
			if (left == null)
				return 1;
			if (right == null)
				return 1;
			else {
				return left.countNodes() + right.countNodes() + 1;
			}
		}

		public void preorder() {
			System.out.print(data + " ");
			if (left != null) {
				left.inorder();
			}

			if (right != null) {
				right.inorder();
			}

		}

		public void postorder() {
			if (left != null) {
				left.inorder();
			}

			if (right != null) {
				right.inorder();
			}
			System.out.print(data + " ");

		}

		public void levelorder(Node node) {
			LinkedList<Node> ll = new LinkedList<Node>();
			ll.add(node);
			getorder(ll);

		}

		public void getorder(LinkedList<Node> ll) {
			while (!ll.isEmpty()) {
				Node node = ll.poll();
				System.out.print(node.data + " ");
				if (node.left != null)
					ll.add(node.left);
				if (node.right != null)
					ll.add(node.right);
			}
		}
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				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());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	static class Pair {
		int first, second;

		public Pair(int first, int second) {
			this.first = first;
			this.second = second;
		}

	}

	static class OutputWriter {
		private final PrintWriter writer;

		public OutputWriter(OutputStream outputStream) {
			writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
		}

		public OutputWriter(Writer writer) {
			this.writer = new PrintWriter(writer);
		}

		public void print(Object... objects) {
			for (int i = 0; i < objects.length; i++) {
				if (i != 0)
					writer.print(' ');
				writer.print(objects[i]);
			}
		}

		public void printLine(Object... objects) {
			print(objects);
			writer.println();
		}

		public void close() {
			writer.close();
		}

		public void flush() {
			writer.flush();
		}

	}

	private static final Scanner sc = new Scanner(System.in);
	private static final FastReader fs = new FastReader();
	private static final OutputWriter op = new OutputWriter(System.out);

	static int[] getintarray(int n) {
		int ar[] = new int[n];
		for (int i = 0; i < n; i++) {
			ar[i] = fs.nextInt();
		}
		return ar;
	}

	static long[] getlongarray(int n) {
		long ar[] = new long[n];
		for (int i = 0; i < n; i++) {
			ar[i] = fs.nextLong();
		}
		return ar;
	}

	static int[][] get2darray(int n, int m) {
		int ar[][] = new int[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				ar[i][j] = fs.nextInt();
			}
		}
		return ar;
	}

	static Pair[] getpairarray(int n) {
		Pair ar[] = new Pair[n];
		for (int i = 0; i < n; i++) {
			ar[i] = new Pair(fs.nextInt(), fs.nextInt());
		}
		return ar;
	}

	static void printarray(int ar[]) {
		for (int i : ar) {
			op.print(i + " ");
		}
		op.flush();
	}

	static int fact(int n) {
		int fact = 1;
		for (int i = 2; i <= n; i++) {
			fact *= i;
		}
		return fact;
	}

//

	// function to find largest prime factor

}


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

public class test {

	public static void main(String[] args) {
		int test = fs.nextInt();
//		int test = 1;
		for (int cases = 0; cases < test; cases++) {
			String s = fs.next();
			char ar[] = s.toCharArray();
			int n = ar.length;
			Set<Character> set = new HashSet<Character>();
			for (int i = 0; i < ar.length; i++) {
				set.add(ar[i]);
			}
			Iterator<Character> iterator = set.iterator();
			TreeSet<Character> ans = new TreeSet<Character>();
			while (iterator.hasNext()) {
				Character character = iterator.next();
				boolean rs = true;
				for (int i = 0; i < n;) {
					int c = 1;
					if (ar[i] == character) {
						int j = i + 1;
						for (; j < n; j++) {
							if (ar[j] == ar[i]) {
								++c;
							} else {
								break;
							}
						}
						i = j;
					} else {
						++i;
						continue;
					}
					if (c % 2 != 0) {
						rs = true;
						break;
					} else if (c % 2 == 0) {
						rs = false;
					}
				}
				if (rs) {
					ans.add(character);
				}
			}
			for (Character character : ans) {
				op.print(character);
			}
			op.print("\n");
			op.flush();
		}
	}

	static int countDifferentBits(int a, int b) {
		int count = 0;
		for (int i = 0; i < 32; i++) {
			if (((a >> i) & 1) != ((b >> i) & 1)) {
				++count;
			}
		}
		return count;
	}

	static int gcd(int a, int b) {
		if (b == 0)
			return a;
		return gcd(b, a % b);
	}

	static void sortMyMapusingValues(HashMap<String, Integer> hm) {

		List<Map.Entry<String, Integer>> capitalList = new LinkedList<>(hm.entrySet());

		Collections.sort(capitalList, new Comparator<Map.Entry<String, Integer>>() {
			public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
				return (o1.getValue()).compareTo(o2.getValue());
			}
		});
		HashMap<String, Integer> result = new HashMap<>();
		for (Map.Entry<String, Integer> entry : capitalList) {
			result.put(entry.getKey(), entry.getValue());
		}
	}

	static boolean ispowerof2(long num) {
		if ((num & (num - 1)) == 0)
			return true;
		return false;
	}

	static void primeFactors(int n) {
		while (n % 2 == 0) {
			System.out.print(2 + " ");
			n /= 2;
		}
		for (int i = 3; i <= Math.sqrt(n); i += 2) {
			while (n % i == 0) {
				System.out.print(i + " ");
				n /= i;
			}
		}
		if (n > 2)
			System.out.print(n);
	}

	static boolean isPrime(int n) {
		// Corner cases
		if (n <= 1)
			return false;
		if (n <= 3)
			return true;
		if (n % 2 == 0 || n % 3 == 0)
			return false;

		for (int i = 5; i * i <= n; i = i + 6)
			if (n % i == 0 || n % (i + 2) == 0)
				return false;

		return true;
	}

	static class Graph {
		HashMap<Integer, LinkedList<Integer>> hm = new HashMap<Integer, LinkedList<Integer>>();

		private void addVertex(int vertex) {
			hm.put(vertex, new LinkedList<>());
		}

		private void addEdge(int source, int dest, boolean bi) {
			if (!hm.containsKey(source))
				addVertex(source);
			if (!hm.containsKey(dest))
				addVertex(dest);
			hm.get(source).add(dest);
			if (bi) {
				hm.get(dest).add(source);
			}
		}

		private boolean uniCycle(int i, HashSet<Integer> visited, int parent) {
			visited.add(i);
			LinkedList<Integer> list = hm.get(i);
			Iterator<Integer> it = list.iterator();
			while (it.hasNext()) {
				Integer integer = (Integer) it.next();
				if (!visited.contains(integer)) {
					if (uniCycle(integer, visited, i))
						return true;
				} else if (integer != parent) {
					return true;
				}
			}
			return false;
		}

		private boolean uniCyclic() {
			HashSet<Integer> visited = new HashSet<Integer>();
			Set<Integer> set = hm.keySet();
			for (Integer integer : set) {
				if (!visited.contains(integer)) {
					if (uniCycle(integer, visited, -1)) {
						return true;
					}
				}
			}
			return false;
		}

		private boolean isbiCycle(int i, HashSet<Integer> visited, HashSet<Integer> countered) {
			if (countered.contains(i))
				return true;
			if (visited.contains(i))
				return false;
			visited.add(i);
			countered.add(i);
			LinkedList<Integer> list = hm.get(i);
			Iterator<Integer> it = list.iterator();
			while (it.hasNext()) {
				Integer integer = (Integer) it.next();
				if (isbiCycle(integer, visited, countered)) {
					return true;
				}
			}
			countered.remove(i);
			return false;
		}

		private boolean isbiCyclic() {
			HashSet<Integer> visited = new HashSet<Integer>();
			HashSet<Integer> countered = new HashSet<Integer>();
			Set<Integer> set = hm.keySet();
			for (Integer integer : set) {
				if (isbiCycle(integer, visited, countered)) {
					return true;
				}
			}
			return false;
		}
	}

	static class Node {
		Node left, right;
		int data;

		public Node(int data) {
			this.data = data;
		}

		public void insert(int val) {
			if (val <= data) {
				if (left == null) {
					left = new Node(val);
				} else {
					left.insert(val);
				}
			} else {
				if (right == null) {
					right = new Node(val);
				} else {
					right.insert(val);
				}
			}
		}

		public boolean contains(int val) {
			if (data == val) {
				return true;
			} else if (val < data) {
				if (left == null) {
					return false;
				} else {
					return left.contains(val);
				}
			} else {
				if (right == null) {
					return false;
				} else {
					return right.contains(val);
				}
			}
		}

		public void inorder() {
			if (left != null) {
				left.inorder();
			}
			System.out.print(data + " ");
			if (right != null) {
				right.inorder();
			}
		}

		public int maxDepth() {
			if (left == null)
				return 0;
			if (right == null)
				return 0;
			else {
				int ll = left.maxDepth();
				int rr = right.maxDepth();
				if (ll > rr)
					return (ll + 1);
				else
					return (rr + 1);
			}
		}

		public int countNodes() {
			if (left == null)
				return 1;
			if (right == null)
				return 1;
			else {
				return left.countNodes() + right.countNodes() + 1;
			}
		}

		public void preorder() {
			System.out.print(data + " ");
			if (left != null) {
				left.inorder();
			}

			if (right != null) {
				right.inorder();
			}

		}

		public void postorder() {
			if (left != null) {
				left.inorder();
			}

			if (right != null) {
				right.inorder();
			}
			System.out.print(data + " ");

		}

		public void levelorder(Node node) {
			LinkedList<Node> ll = new LinkedList<Node>();
			ll.add(node);
			getorder(ll);

		}

		public void getorder(LinkedList<Node> ll) {
			while (!ll.isEmpty()) {
				Node node = ll.poll();
				System.out.print(node.data + " ");
				if (node.left != null)
					ll.add(node.left);
				if (node.right != null)
					ll.add(node.right);
			}
		}
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				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());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	static class Pair {
		int first, second;

		public Pair(int first, int second) {
			this.first = first;
			this.second = second;
		}

	}

	static class OutputWriter {
		private final PrintWriter writer;

		public OutputWriter(OutputStream outputStream) {
			writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
		}

		public OutputWriter(Writer writer) {
			this.writer = new PrintWriter(writer);
		}

		public void print(Object... objects) {
			for (int i = 0; i < objects.length; i++) {
				if (i != 0)
					writer.print(' ');
				writer.print(objects[i]);
			}
		}

		public void printLine(Object... objects) {
			print(objects);
			writer.println();
		}

		public void close() {
			writer.close();
		}

		public void flush() {
			writer.flush();
		}

	}

	private static final Scanner sc = new Scanner(System.in);
	private static final FastReader fs = new FastReader();
	private static final OutputWriter op = new OutputWriter(System.out);

	static int[] getintarray(int n) {
		int ar[] = new int[n];
		for (int i = 0; i < n; i++) {
			ar[i] = fs.nextInt();
		}
		return ar;
	}

	static long[] getlongarray(int n) {
		long ar[] = new long[n];
		for (int i = 0; i < n; i++) {
			ar[i] = fs.nextLong();
		}
		return ar;
	}

	static int[][] get2darray(int n, int m) {
		int ar[][] = new int[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				ar[i][j] = fs.nextInt();
			}
		}
		return ar;
	}

	static Pair[] getpairarray(int n) {
		Pair ar[] = new Pair[n];
		for (int i = 0; i < n; i++) {
			ar[i] = new Pair(fs.nextInt(), fs.nextInt());
		}
		return ar;
	}

	static void printarray(int ar[]) {
		for (int i : ar) {
			op.print(i + " ");
		}
		op.flush();
	}

	static int fact(int n) {
		int fact = 1;
		for (int i = 2; i <= n; i++) {
			fact *= i;
		}
		return fact;
	}

//

	// function to find largest prime factor

}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Solution {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int numOfTests = scanner.nextInt();
        String source;
        for (int i = 0; i < numOfTests; i++) {
            source = scanner.next();
            solve(source);
        }
    }

    private static void solve(String source) {
        List<Character> letters = new ArrayList<>();
        int tmpPointer = 0;
        char tmpChar;
        while (tmpPointer < source.length()) {
            tmpChar = source.charAt(tmpPointer);
            if (tmpPointer == source.length() - 1) {
                letters.add(tmpChar);
            } else if (source.charAt(tmpPointer + 1) == tmpChar) {
                tmpPointer++;
            } else {
                letters.add(tmpChar);
            }
            tmpPointer++;
        }
        letters.sort(Character::compareTo);
        for (Character tempChar : letters) {
            System.out.print(tempChar);
        }
        System.out.println();
    }
}


import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Solution {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int numOfTests = scanner.nextInt();
        String source;
        for (int i = 0; i < numOfTests; i++) {
            source = scanner.next();
            solve(source);
        }
    }

    private static void solve(String source) {
        List<Character> letters = new ArrayList<>();
        int tmpPointer = 0;
        char tmpChar;
        while (tmpPointer < source.length()) {
            tmpChar = source.charAt(tmpPointer);
            if (tmpPointer == source.length() - 1) {
                if (!letters.contains(tmpChar)) {
                    letters.add(tmpChar);
                }
            } else if (source.charAt(tmpPointer + 1) == tmpChar) {
                tmpPointer++;
            } else {
                if (!letters.contains(tmpChar)) {
                    letters.add(tmpChar);
                }
            }
            tmpPointer++;
        }
        letters.sort(Character::compareTo);
        for (Character tempChar : letters) {
            System.out.print(tempChar);
        }
        System.out.println();
    }
}


import java.io.*;
import java.util.*;
public class Solution {
		static int MAX = (int)1e5+1;
		public static void main(String[] args)throws Exception{
			//InputReader input = new InputReader(System.in);
			Scanner input = new Scanner(System.in);
			OutputStreamWriter out = new OutputStreamWriter(System.out);
			int test = input.nextInt();
			while(test-->0) {
				String s = input.next();
				int n = s.length();
				TreeSet<Character>set = new TreeSet<>();
				//System.out.println(s);
				for(char ch = 'a';ch<='z';ch++) {
					int count1 =0;
					int count2 = 0;
					for(int i =0;i<n;i++) {
						while(i<n && s.charAt(i) == ch) {
							count1++;
							i++;
						}
						if(count1%2 == 1)break;
					}
					if(count1%2 == 1)set.add(ch);
				}
				for(char it:set)System.out.print(it);
				System.out.println();
			}
		}

}

class InputReader {
	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1) {
			throw new InputMismatchException();
		}
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0) {
				return -1;
			}
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public double readDouble() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		double res = 0;
		while (!isSpaceChar(c) && c != '.') {
			if (c == 'e' || c == 'E') {
				return res * Math.pow(10, readInt());
			}
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		}
		if (c == '.') {
			c = read();
			double m = 1;
			while (!isSpaceChar(c)) {
				if (c == 'e' || c == 'E') {
					return res * Math.pow(10, readInt());
				}
				if (c < '0' || c > '9') {
					throw new InputMismatchException();
				}
				m /= 10;
				res += (c - '0') * m;
				c = read();
			}
		}
		return res * sgn;
	}

	public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public boolean isSpaceChar(int c) {
		if (filter != null) {
			return filter.isSpaceChar(c);
		}
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public String next() {
		return readString();
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}


import java.io.*;
import java.util.*;
public class Solution {
		static int MAX = (int)1e5+1;
		public static void main(String[] args)throws Exception{
			//InputReader input = new InputReader(System.in);
			Scanner input = new Scanner(System.in);
			OutputStreamWriter out = new OutputStreamWriter(System.out);
			int test = input.nextInt();
			while(test-->0) {
				String s = input.next();
				int n = s.length();
				TreeSet<Character>set = new TreeSet<>();
				//System.out.println(s);
				for(char ch = 'a';ch<='z';ch++) {
					int count1 =0;
					int count2 = 0;
					for(int i =0;i<n;i++) {
						if(s.charAt(i) == ch) {count1++;
							if(i+1<n && s.charAt(i+1) == ch)count1--;
							else if(i-1>=0 && s.charAt(i-1) == ch)count1--;
						}
					}
					if(count1 >0)set.add(ch);
				}
				for(char it:set)System.out.print(it);
				System.out.println();
			}
		}

}

class InputReader {
	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1) {
			throw new InputMismatchException();
		}
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0) {
				return -1;
			}
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public double readDouble() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		double res = 0;
		while (!isSpaceChar(c) && c != '.') {
			if (c == 'e' || c == 'E') {
				return res * Math.pow(10, readInt());
			}
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		}
		if (c == '.') {
			c = read();
			double m = 1;
			while (!isSpaceChar(c)) {
				if (c == 'e' || c == 'E') {
					return res * Math.pow(10, readInt());
				}
				if (c < '0' || c > '9') {
					throw new InputMismatchException();
				}
				m /= 10;
				res += (c - '0') * m;
				c = read();
			}
		}
		return res * sgn;
	}

	public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public boolean isSpaceChar(int c) {
		if (filter != null) {
			return filter.isSpaceChar(c);
		}
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public String next() {
		return readString();
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}


// import java.util.Scanner;
// import java.util.Set;
// import java.util.HashSet;
// import java.util.Arrays;
import java.util.*;

public class BrokenKeyboard{

	public static void solve(String input){
		boolean[] abc = new boolean[26];

		for(int i=0; i<input.length(); i++){
			int j=i;
			while(j+1 < input.length() && input.charAt(i) == input.charAt(j+1)){
				j++;
			}
			if((j-i)%2 == 0){
				abc[input.charAt(i)-'a'] = true;
			}
			i = j;
		}

		for(int i=0; i<26; i++){
			if(abc[i]){
				System.out.print((char)('a'+i));
			}
		}
		System.out.println();
	}

	public static void main(String[] arguments){
		Scanner scan = new Scanner(System.in);
		int numberOfTests = scan.nextInt();

		for(int i=0; i<numberOfTests; i++){
			solve(scan.next());
		}
	}
}


import java.util.Scanner;

public class BearAndBigBrother{
	public static void main(String[] arguments){
		Scanner scan = new Scanner(System.in);
		int n=0;
		int limakWeight = scan.nextInt();
		int bobWeight = scan.nextInt();

		while(limakWeight <= bobWeight){
			limakWeight*=3;
			bobWeight*=2;
			n++;
		}
		System.out.println(n);
	}
}


/**
 * @author egaeus
 * @mail sebegaeusprogram@gmail.com
 * @veredict Accepted
 * @url <https://codeforces.com/problemset/problem/1251/A>
 * @category implementation
 * @date 24/10/2019
 **/

import java.io.BufferedReader;
import java.io.InputStreamReader;

import static java.lang.Integer.parseInt;

public class CF1251A {
    public static void main(String args[]) throws Throwable {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        for (int Q = parseInt(in.readLine()), q = 0; q++ < Q; ) {
            char[] a = in.readLine().toCharArray();
            boolean[] A = new boolean[26];
            int c = 1;
            for (int i = 1; i < a.length; i++) {

                if (a[i] == a[i - 1]) c++;
                else {
                    if (c % 2 == 1) {
                        A[a[i - 1] - 'a'] = true;

                    }
                    c = 1;
                }
            }
            if (c % 2 == 1) A[a[a.length - 1] - 'a'] = true;
            String s = "";
            for (int i = 0; i < 26; i++)
                if (A[i]) s += (char) (i + 'a');
            System.out.println(s);
        }
    }
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        List<StringBuilder> inputStrings = new ArrayList<>();
        Scanner in = new Scanner(System.in);

        int countOfInputs = in.nextInt();
        in.nextLine();

        for (int i = 0; i < countOfInputs; i++) {
            inputStrings.add(new StringBuilder(in.nextLine()));
        }

        for (int i = 0; i < countOfInputs; i++) {
            StringBuilder result = new StringBuilder();
            StringBuilder string = inputStrings.get(i);

            Character element = string.charAt(0);
            int sequenceLength = 1;

            for (int j = 1; j < string.length(); j++) {
                if (element.equals(string.charAt(j))) {
                    sequenceLength++;
                } else {
                    if (sequenceLength % 2 != 0) {
                        result.append(element);
                    }
                    element = string.charAt(j);
                    sequenceLength = 1;
                }
            }
            if (sequenceLength % 2 != 0) {
                result.append(element);
            }

            char[] resultArray = result.toString().toCharArray();
            Arrays.sort(resultArray);
            System.out.println(resultArray);
        }
    }

}


package com.company;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        List<StringBuilder> inputStrings = new ArrayList<>();
        Scanner in = new Scanner(System.in);

        int countOfInputs = in.nextInt();
        in.nextLine();

        for (int i = 0; i < countOfInputs; i++) {
            inputStrings.add(new StringBuilder(in.nextLine()));
        }

        for (int i = 0; i < countOfInputs; i++) {
            StringBuilder result = new StringBuilder();
            StringBuilder string = inputStrings.get(i);

            Character element = string.charAt(0);
            int sequenceLength = 1;

            for (int j = 1; j < string.length(); j++) {
                if (element.equals(string.charAt(j))) {
                    sequenceLength++;
                } else {
                    if (sequenceLength % 2 != 0) {
                        result.append(element);
                    }
                    element = string.charAt(j);
                    sequenceLength = 1;
                }
            }
            if (sequenceLength % 2 != 0) {
                result.append(element);
            }

            char[] resultArray = result.toString().toCharArray();
            Arrays.sort(resultArray);
            System.out.println(resultArray);
        }
    }

}


//package com.company;

import java.util.*;

public class Main {

    public static void main(String[] args) {
        List<StringBuilder> inputStrings = new ArrayList<>();
        Scanner in = new Scanner(System.in);

        int countOfInputs = in.nextInt();
        in.nextLine();

        for (int i = 0; i < countOfInputs; i++) {
            inputStrings.add(new StringBuilder(in.nextLine()));
        }

        for (int i = 0; i < countOfInputs; i++) {
            TreeSet<Character> result = new TreeSet<>();
            StringBuilder string = inputStrings.get(i);

            Character element = string.charAt(0);
            int sequenceLength = 1;

            for (int j = 1; j < string.length(); j++) {
                if (element.equals(string.charAt(j))) {
                    sequenceLength++;
                } else {
                    if (sequenceLength % 2 != 0) {
                        result.add(element);
                    }
                    element = string.charAt(j);
                    sequenceLength = 1;
                }
            }
            if (sequenceLength % 2 != 0) {
                result.add(element);
            }

            StringBuilder resultBuilder = new StringBuilder();
            result.forEach(resultBuilder::append);
            System.out.println(resultBuilder);
        }
    }

}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author tarek
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        ABrokenKeyboard solver = new ABrokenKeyboard();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABrokenKeyboard {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int t = in.readInt();
            boolean[] arr = new boolean[26];
            while (t-- > 0) {
                char[] a = in.readLine().toCharArray();
                Arrays.fill(arr, false);
                for (int i = 0; i < a.length; i++) {
                    if (i != a.length - 1 && a[i] == a[i + 1]) {
                        i++;
                    } else {
                        arr[a[i] - 'a'] = true;
                    }
                }
                StringBuilder s = new StringBuilder();
                for (int i = 0; i < 26; i++) {
                    if (arr[i]) {
                        s.append((char) (((int) 'a') + i));
                    }
                }
                out.printLine(s.toString());
            }
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private String readLine0() {
            StringBuilder buf = new StringBuilder();
            int c = read();
            while (c != '\n' && c != -1) {
                if (c != '\r') {
                    buf.appendCodePoint(c);
                }
                c = read();
            }
            return buf.toString();
        }

        public String readLine() {
            String s = readLine0();
            while (s.trim().length() == 0) {
                s = readLine0();
            }
            return s;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void printLine(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }
}


import java.util.*;
public class BrokenKeyboard{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        sc.nextLine();
        for (int z = 0; z < t; z++) {
            boolean letters[]=new boolean[26];
            String query=sc.nextLine();
            int i=0;
            while(i<query.length()-1){
                if(query.charAt(i)==query.charAt(i+1)){
                    i+=2;
                }
                else{
                    letters[query.charAt(i)-'a']=true;
                    i++;
                }
            }
            if(i==query.length()-1)
                letters[query.charAt(i)-'a']=true;
            for (i = 0; i < 26; i++) {
                if(letters[i])
                    System.out.print(((char)(i+'a')));
            }
            System.out.println();
        }
        sc.close();
    }
}


import java.util.*;
public class BrokenKeyboard{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        sc.nextLine();
        for (int z = 0; z < t; z++) {
            int letters[]=new int[26];
            String query=sc.nextLine();
            for (int i = 0; i < query.length(); i++) {
                letters[query.charAt(i)-'a']++;
            }
            for (int i = 0; i < 26; i++) {
                if(letters[i]%2!=0)
                    System.out.print(((char)(i+'a')));
            }
            System.out.println();
        }
        sc.close();
    }
}


import java.util.Scanner;

public class hello {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int[] alph = new int[26];
        int t = input.nextInt();
        while (t > 0) {
            char[] s = input.next().toCharArray();
            for (int i = 0; i < s.length; ++i) {
                if (alph[s[i] - 97] == 0) {
                    alph[s[i] - 97] = 1;
                    int j = i;
                    int n = 0;
                    for (; j < s.length; ++j) {
                        if (s[j] == s[i])
                            ++n;
                        if ((s[j] != s[i] && n > 0) || j + 1 == s.length) {
                            if (n % 2 == 1) {
                                alph[s[i] - 97] = 2;
                                break;
                            }
                            n = 0;
                        }
                    }
                }
            }
            for (int i = 0; i < 26; ++i) {
                if (alph[i] == 2)
                    System.out.print((char) (97 + i));
                alph[i] = 0;
            }
            System.out.print('\n');
            --t;
        }
        input.close();
    }
}


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

public class Solution{

    public static void main(String[] args) throws Exception{
        BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(buffer.readLine());
        while(N-- > 0){
            String[] word1 = buffer.readLine().split("");
            String[] ww = new String[word1.length];
            int counter = 0;
            if(word1.length == 1){
                System.out.println(word1[0]);
                continue;
            }
            boolean[] check = new boolean[26];
            int i;
            for(i=0; i<word1.length-1; i++){
                if(!word1[i].equals(word1[i+1]) && !check[(int)word1[i].charAt(0)-97]){
                    check[(int)word1[i].charAt(0)-97] = true;
                    //System.out.print(word1[i] + "");
                    ww[counter++] = word1[i];

                }
                if(word1[i].equals(word1[i+1]))
                    i++;
            }
            if(i == word1.length && counter == 0)
                System.out.println();

            else{
               // System.out.println(counter);
                if(i == word1.length-1)
                ww[counter++] = word1[i];

                MergeSort merger = new MergeSort();
                merger.sort(ww,0,counter-1);
                for(int j=0;j<counter; j++)
                    System.out.print(ww[j] + "");
                System.out.println();
            }

        }
    }

    static class MergeSort{

        public void sort(String[] arr, int low, int high){
            if(low < high){
                int middle = low + (high-low)/2;
                sort(arr, low, middle);
                sort(arr, middle+1, high);
                merge(arr, low, middle, high);
            }
        }

        public void merge(String[] arr, int low, int middle, int high){
            int n1 = middle - low + 1;
            int n2 = high - middle;

            String[] s1 = new String[n1];
            String[] s2 = new String[n2];

            for(int i=0; i<n1;i++){
                s1[i] = arr[low + i];
            }

            for(int i=0; i<n2;i++){
                s2[i] = arr[middle + 1 + i];
            }

            int a=0, b=0, c= low;

            while(a<n1 && b<n2){
                if(s1[a].compareTo(s2[b]) <= 0){
                    arr[c++] = s1[a++];
                }
                else{
                    arr[c++] = s2[b++];
                }
            }

            for( ; a<n1;a++)
                arr[c++] = s1[a];

            for( ; b<n2;b++)
                arr[c++] = s2[b];
        }
    }

}


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

public class Solution{

    public static void main(String[] args) throws Exception{
        BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(buffer.readLine());
        while(N-- > 0){
            String[] word1 = buffer.readLine().split("");
           // String[] ww = new String[word1.length];
            int counter = 0;
            if(word1.length == 1){
                System.out.println(word1[0]);
                continue;
            }
            boolean[] check = new boolean[26];
            int i;
            for(i=0; i<word1.length-1; i++){
                if(!word1[i].equals(word1[i+1]) && !check[(int)word1[i].charAt(0)-97]){
                    check[(int)word1[i].charAt(0)-97] = true;
                    counter++;
                    //System.out.print(word1[i] + "");
                 //   ww[counter++] = word1[i];

                }
                if(word1[i].equals(word1[i+1]))
                    i++;
            }
            if(i == word1.length-1 || i == word1.length){
                if(i == word1.length - 1)
                    check[(int)word1[i].charAt(0)-97] = true;
                for(i=0; i<26; i++){
                if(check[i]){
                    System.out.print(Character.toString((char)(i+97)));
                }
                }
                System.out.println();
                continue;
            }

            if(counter == 0)
                System.out.println();

        }
    }

}


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

public class Solution{

    public static void main(String[] args) throws Exception{
        BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(buffer.readLine());
        while(N-- > 0){
            String[] word1 = buffer.readLine().split("");
            String[] ww = new String[word1.length];
            int counter = 0;
            if(word1.length == 1){
                System.out.println(word1[0]);
                continue;
            }
            boolean[] check = new boolean[26];
            int i;
            for(i=0; i<word1.length-1; i++){
                if(!word1[i].equals(word1[i+1]) && !check[(int)word1[i].charAt(0)-97]){
                    check[(int)word1[i].charAt(0)-97] = true;
                    //System.out.print(word1[i] + "");
                    ww[counter++] = word1[i];

                }
                if(word1[i].equals(word1[i+1]))
                    i++;
            }
            if(i == word1.length && counter == 0 && !check[i])
                System.out.println();

            else{
               // System.out.println(counter);
                if(i == word1.length-1)
                ww[counter++] = word1[i];

                MergeSort merger = new MergeSort();
                merger.sort(ww,0,counter-1);
                for(int j=0;j<counter; j++)
                    System.out.print(ww[j] + "");
                System.out.println();
            }

        }
    }

    static class MergeSort{

        public void sort(String[] arr, int low, int high){
            if(low < high){
                int middle = low + (high-low)/2;
                sort(arr, low, middle);
                sort(arr, middle+1, high);
                merge(arr, low, middle, high);
            }
        }

        public void merge(String[] arr, int low, int middle, int high){
            int n1 = middle - low + 1;
            int n2 = high - middle;

            String[] s1 = new String[n1];
            String[] s2 = new String[n2];

            for(int i=0; i<n1;i++){
                s1[i] = arr[low + i];
            }

            for(int i=0; i<n2;i++){
                s2[i] = arr[middle + 1 + i];
            }

            int a=0, b=0, c= low;

            while(a<n1 && b<n2){
                if(s1[a].compareTo(s2[b]) <= 0){
                    arr[c++] = s1[a++];
                }
                else{
                    arr[c++] = s2[b++];
                }
            }

            for( ; a<n1;a++)
                arr[c++] = s1[a];

            for( ; b<n2;b++)
                arr[c++] = s2[b];
        }
    }

}


import java.util.*;

public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t > 0) {
            String s = sc.next();
            ArrayList<Character> confirmed = new ArrayList<>();
            ArrayList<Character> malfunctioned = new ArrayList<>();

            for(int i=0;i<s.length()-1;){
                char toCheck = s.charAt(i);
                int count = 1;
                while (i<s.length()-1 && s.charAt(i+1)==toCheck){
                    count++;
                    i++;
                }
                if(count%2==0 && !confirmed.contains(toCheck)){
                    malfunctioned.add(toCheck);
                }else {
                    if(!confirmed.contains(toCheck)) confirmed.add(toCheck);
//                    if(malfunctioned.contains(toCheck)) malfunctioned.remove(toCheck);
                }
                i++;
             }

            if(s.length()==1) confirmed.add(s.charAt(0));
            if(s.length() > 1 && s.charAt(s.length()-1) != s.charAt(s.length()-2)){
                char toCheck = s.charAt(s.length()-1);
                if(!confirmed.contains(toCheck)) confirmed.add(toCheck);
            }
            Collections.sort(confirmed);
            StringBuilder sb = new StringBuilder();
            for(int i=0;i<confirmed.size();i++) sb.append(confirmed.get(i));
            System.out.println(sb);
            t--;
        }
    }
}


import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        String str1 = sc.nextLine();

        for(int i = 0; i < a; i++){
            //System.out.println(i);
            String str = sc.nextLine();
            //System.out.println(str);
            char[] mass = new char[str.length()];
            for(int v = 0; v<str.length(); v++) {
                mass[v] = str.charAt(v);
            }
            ArrayList<Character> results = new ArrayList<>();
            for(int m = 0;m<str.length(); m++){
                if(m==str.length()-1) {
                    //System.out.println(mass[m]);
                    results.add(mass[m]);
                }
                else if(mass[m]==mass[m+1]){
                    m++;
                }
                else {
                    //System.out.println(mass[m]);
                    results.add(mass[m]);
                }
            }
            Collections.sort(results);
            for(int k = 0 ; k<results.size(); k++){
                System.out.print(results.get(k));
            }
            System.out.println();
        }
    }
}


import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        String str1 = sc.nextLine();

        for(int i = 0; i < a; i++){
            //System.out.println(i);
            String str = sc.nextLine();
            //System.out.println(str);
            char[] mass = new char[str.length()];
            for(int v = 0; v<str.length(); v++) {
                mass[v] = str.charAt(v);
            }
            ArrayList<Character> results = new ArrayList<>();
            for(int m = 0;m<str.length(); m++){

                if(m==str.length()-1) {
                    if(!results.contains(mass[m]))
                        results.add(mass[m]);
                }
                else if(mass[m]==mass[m+1]){
                    m++;
                }
                else {
                    if(!results.contains(mass[m]))
                        results.add(mass[m]);
                }
            }
            Collections.sort(results);
            for(int k = 0 ; k<results.size(); k++){
                System.out.print(results.get(k));
            }
            System.out.println();
        }
    }
}