// Arup Guha
// 10/17/2014
// Solution to 1994 UCF HS Contest Problem: Base Alphabets

import java.util.*;

public class base {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);

		while (stdin.hasNext()) {

			// Read input & calculate unique letters.
			String s = stdin.next();
			String t = stdin.next();
			int maskS = getMask(s);
			int maskT = getMask(t);

			// Echo output.
			System.out.println(s);
			System.out.println(t);

			// Print appropriate message.
			if (maskS == maskT)
				System.out.println("The words share the base alphabet "+getLetters(maskS)+".");
			else
				System.out.println("The words do not share the same base alphabet.");
			System.out.println();
		}
	}

	// Returns a mask that stores 1 in bit i if letter i is in s.
	public static int getMask(String s) {
		int mask = 0;
		for (int i=0; i<s.length(); i++)
			mask |= (1 << (s.charAt(i)-'a'));
		return mask;
	}

	public static String getLetters(int mask) {

		// Build this string.
		String ans = "(";

		// Annoying, for comma...
		int bitsOn = Integer.bitCount(mask), curBits = 0;

		// Go through each letter.
		for (int i=0; i<26; i++) {

			// See if this letter is in our list.
			if ( (mask & (1 << i)) > 0) {
				curBits++;
				ans = ans + (char)('a'+i);
				if (curBits < bitsOn)
					ans = ans + ", ";
			}
		}

		// End the string and return.
		ans = ans + ")";
		return ans;
	}
}