In mathematics, a subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. For example, the sequence BDF is a subsequence of ABCDEF. A substring of a string is a continuous subsequence of the string. For example, BCD is a substring of ABCDEF.

You are given two strings s1, s2 and another string called virus. Your task is to find the longest common subsequence of s1 and s2, such that it doesn't contain virus as a substring.

Input

The input contains three strings in three separate lines: s1, s2 and virus (1 ≤ |s1|, |s2|, |virus| ≤ 100). Each string consists only of uppercase English letters.

Output

Output the longest common subsequence of s1 and s2 without virus as a substring. If there are multiple answers, any of them will be accepted. 

If there is no valid common subsequence, output 0.

Examples

Input

AJKEQSLOBSROFGZ
OVGURWZLWVLUXTH
OZ


Output

ORZ


Input

AA
A
A


Output

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

public class Main {

	BufferedReader in;
	StringTokenizer str = null;
	PrintWriter out;
	
	private String next() throws Exception{
		while (str == null || !str.hasMoreElements())
			str = new StringTokenizer(in.readLine());
		return str.nextToken();
	}
	
	private int nextInt() throws Exception{
		return Integer.parseInt(next());
	}
	
	private long nextLong() throws Exception{
		return Long.parseLong(next());
	}
	
	private double nextDouble() throws Exception{
		return Double.parseDouble(next());
	}

	V []tree;
	int size = 0;

	int n, m, v;
	char []a, b, c;

	int [][][]dp;

	public void run() throws Exception{
		in =  new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		a = next().toCharArray();
		b = next().toCharArray();
		c = next().toCharArray();

		n = a.length;
		m = b.length;
		v = c.length;

		init();
		addString(c);

		for(int i = 0; i < size; ++i) getLink(i);
		// for(int i = 0; i < size; ++i) System.out.println(i + " " + tree[i]);

		dp = new int[n][m][v];
		for(int [][]i : dp)
			for(int []j : i)
				Arrays.fill(j, -1);
		int ret = dp(0, 0, 0);
		// out.println(ret);
		if (ret <= 0) {
			out.println(0);
		}else {
			print(0, 0, 0);
			out.println();
		}
		out.close();
	}

	final static int oo = Integer.MAX_VALUE / 2;

	private void print(int i, int j, int k) {
		if (i == n) return;
		if (j == m) return;

		// System.out.println(i + " "  + j + " " + k + " " + dp[i][j][k]);

		if (a[i] == b[j]) {
			int which = 0;
			int ret = dp(i + 1, j, k);
			if (ret < dp(i, j + 1, k)) {
				ret = dp(i, j + 1, k);
				which = 1;
			}

			int c = a[i] - 'A';
			int next = go(k, c);
			if (next != v) {
				if (ret <= dp(i + 1, j + 1, next)) {
					ret = dp(i + 1, j + 1, next);
					which = 2;
				}
			}

			if (which == 0) {
				print(i + 1, j, k);
			}else if (which == 1) {
				print(i, j + 1, k);
			}else {
				out.print(a[i]);
				print(i + 1, j + 1, next);
			}
		}else {
			int ret = dp(i + 1, j, k);
			if (ret < dp(i, j + 1, k)) {
				print(i, j + 1, k);
			}else {
				print(i + 1, j, k);
			}
		}
	}

	private int dp(int i, int j, int k) {
		if (k == v) return -oo;
		if (i == n) return 0;
		if (j == m) return 0;

		if (dp[i][j][k] != -1)
			return dp[i][j][k];

		int ret = -oo;
		if (a[i] == b[j]) {
			int c = a[i] - 'A';
			int next = go(k, c);
			if (next != v) {
				ret = Math.max(ret, 1 + dp(i + 1, j + 1, next));	
			}
		}

		ret = Math.max(ret, dp(i, j + 1, k));
		ret = Math.max(ret, dp(i + 1, j, k));	
		
		return dp[i][j][k] = ret;
	}

	private void init() {
		tree = new V[110];
		tree[size++] = new V(-1, -1);
	}

	private void addString(char []a) {
		int v = 0;
		for(int i = 0; i < a.length; ++i) {
			int c = a[i] - 'A';
			if (tree[v].next[c] == -1) {
				tree[size] = new V(v, c);
				tree[v].next[c] = size++;
			}
			v = tree[v].next[c];
		}
		tree[v].leaf = true;
	}

	private int getLink(int v) {
		if (tree[v].link != -1) return tree[v].link;
		if (v == 0 || tree[v].p == 0) return tree[v].link = 0;
		return tree[v].link = go(getLink(tree[v].p), tree[v].pchar);
	}

	private int go(int v, int c) {
		if (tree[v].go[c] != -1) return tree[v].go[c];
		if (tree[v].next[c] != -1) return tree[v].go[c] = tree[v].next[c];
		if (v == 0) return tree[v].go[c] = 0;
		return tree[v].go[c] = go(getLink(v), c);
	}

	class V {
		int []next, go;
		int p, pchar;
		boolean leaf;
		int link;

		public V(int p, int pchar) {
			this.p = p;
			this.pchar = pchar;
			link = -1;
			leaf = false;
			next = new int[26];
			go = new int[26];
			Arrays.fill(next, -1);
			Arrays.fill(go, -1);
		}

		public String toString() {
			return "[ parent=" + p + " pchar=" + pchar + " link=" + link + " ]"; 
		}
	}
		
	public static void main(String[] args) throws Exception{
		new Main().run();
	}
}
