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.io.*;
import java.util.*;

public class Main{
	static char[]P;//the pattern that need to be found in the text
	static int m;
	static int[]b;
	
	static void kmpPreprocess() {
		m=P.length;
		b=new int[m+1];
		int i = 0, j = -1; b[0] = -1;
		while (i < m) {
			while (j >= 0 && P[i] != P[j]) j = b[j];
			i++; j++;
			b[i] = j;
		} 
	}
	static char[]s,t;
	static int[][][]memo;
	static int[][]nxt;
	static int dp(int i,int j,int k) {
		if(k==m) {
			//has P as substring
			return -1000000000;
		}
		if(i>=s.length || j>=t.length)return 0;
		if(memo[i][j][k]!=-1)return memo[i][j][k];
		
		int match=s[i]==t[j]?(1+dp(i+1, j+1, nxt[k][s[i]-'A'])):0;
		int notMatch=Math.max(dp(i+1, j, k), dp(i, j+1, k));
		return memo[i][j][k]=Math.max(match, notMatch);
	}
	static void trace(int i,int j,int k) {
		if(i>=s.length || j>=t.length)return;
		
		int ans=dp(i, j, k);
		
		int match=s[i]==t[j]?(1+dp(i+1, j+1, nxt[k][s[i]-'A'])):0;
		
		if(ans==match && match!=0) {
			pw.print(s[i]);
			trace(i+1, j+1, nxt[k][s[i]-'A']);
			return;
		}
		if(ans==dp(i+1, j, k)) {
			trace(i+1, j, k);
			return;
		}
		trace(i, j+1, k);
			
	}
	static void main() throws Exception{
		s=sc.nextLine().toCharArray();
		t=sc.nextLine().toCharArray();
		P=sc.nextLine().toCharArray();
		kmpPreprocess();
		nxt=new int[m][26];
		for(int i=0;i<m;i++) {
			for(char c='A';c<='Z';c++) {
				if(c==P[i]) {
					nxt[i][c-'A']=i+1;
				}
				else {
					if(i==0) {
						nxt[i][c-'A']=0;
					}
					else
						nxt[i][c-'A']=nxt[b[i]][c-'A'];
				}
			}
		}
		memo=new int[s.length][t.length][m];
		for(int i=0;i<s.length;i++) {
			for(int j=0;j<t.length;j++) {
				for(int k=0;k<m;k++) {
					memo[i][j][k]=-1;
				}
			}
		}
		if(dp(0, 0, 0)==0) {
			pw.println(0);
			return;
		}
		trace(0, 0, 0);
	}
	public static void main(String[] args) throws Exception{
		sc=new MScanner(System.in);
		pw = new PrintWriter(System.out);
		int tc=1;
//		tc=sc.nextInt();
		while(tc-->0)
			main();
		pw.flush();
	}
	static PrintWriter pw;
	static MScanner  sc;
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] intArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] longArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public int[] intSortedArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public long[] longSortedArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public Integer[] IntegerArr(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] LongArr(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
	static void shuffle(int[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			int tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
	static void shuffle(long[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			long tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
}