// Arup Guha
// 7/13/2026
// Solution to 1994 UCF HSPT Problem: Base Alphabets

import java.util.*;

public class base {
	
	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		
		// Process cases.
		while (stdin.hasNext()) {
		
			// Get input.
			String s1 = stdin.next();
			String s2 = stdin.next();
			boolean[] s1Used = getUsed(s1);
			boolean[] s2Used = getUsed(s2);
			char[] out = getCommonIfEq(s1Used, s2Used);
			
			// For every case.
			System.out.println(s1);
			System.out.println(s2);
			
			// Get this case out of the way.
			if (out == null) {
				System.out.println("The words do not share the same base alphabet.");
			}
			
			// Matching case.
			else {
			
				// Prefix.
				System.out.print("The words share the base alphabet (");
				
				// All letters but last.
				for (int i=0; i<out.length-1; i++)
					System.out.print(out[i]+", ");
					
				// Last letter.
				System.out.println(out[out.length-1]+").");
			}
			
			// Extra blank line.
			System.out.println();
		}
	}
	
	// Returns an used array of letters (lowercase) appearing in s.
	public static boolean[] getUsed(String s) {
		
		// Mark each letter and return.
		boolean[] res = new boolean[26];
		for (int i=0; i<s.length(); i++)
			res[s.charAt(i)-'a'] = true;
		return res;
	}
	
	// Returns null if used1 and used2 are NOT identical. If identical, returns a list
	// of the letters marked in used1.
	public static char[] getCommonIfEq(boolean[] used1, boolean[] used2) {
	
		// Stores number of true entries in used1.
		int cnt = 0;
		
		// Go through both arrays.
		for (int i=0; i<used1.length; i++) {
		
			// Not a match, we can just return null.
			if (used1[i] != used2[i]) return null;
			
			// Update our count, if necessary.
			if (used1[i]) cnt++;
		}
		
		// Space for our answer.
		char[] res = new char[cnt];
		int idx = 0;
		
		// Put in letters.
		for (int i=0; i<used1.length; i++)
			if (used1[i])
				res[idx++] = (char)('a'+i);
		
		// Return!
		return res;
	}

}