// Arup Guha
// 11/15/2014
// Solution to 2014 South East Regional D1 Problem : Word Ladder

import java.util.*;

public class ladder {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int n = stdin.nextInt();

		// Read words.
		String[] words = new String[n];
		for (int i=0; i<n; i++)
			words[i] = stdin.next();

		// Set up priority queue.
		PriorityQueue<node> q = new PriorityQueue<node>();
		q.offer(new node(words[0], 0, 0));
		boolean[][] used = new boolean[n][2];
		boolean solved = false;

		// Run modified BFS.
		while (q.size() > 0) {

			// Get next.
			node next = q.poll();
			int conI = next.usedLink ? 1:0;
			used[next.index][conI] = true;

			// Found it.
			if (next.word.equals(words[1])) {

				// Print connector.
				if (next.usedLink) 	System.out.println(next.connector);
				else 				System.out.println(0);

				// And distance.
				System.out.println(next.distance);

				// Mark and exit.
				solved = true;
				break;
			}

			for (int i=0; i<n; i++) {

				// Regular enqueue case, no new word.
				if (distance(next.word, words[i]) == 1) {
					if (!next.usedLink && !used[i][0])
						q.offer(new node(words[i], next.distance+1, i));
					else if (!used[i][1])
						q.offer(new node(words[i], next.distance+1, next.connector, i));
				}

				// Fake word comes into play!
				else if (distance(next.word, words[i]) == 2 && !next.usedLink && !used[i][1])
					q.offer(new node(words[i], next.distance+2, getConnector(next.word, words[i]), i));
			}
		}

		// Output for not solved case.
		if (!solved) {
			System.out.println(0);
			System.out.println(-1);
		}
	}

	// Returns the alphabetically first connector betwene start and end. Assumes exactly 2 differences.
	public static String getConnector(String start, String end) {
		String ans = "";
		boolean used = false, skipflip = false;
		for (int i=0; i<start.length(); i++) {

			// Keep same character.
			if (start.charAt(i) == end.charAt(i) || used) ans = ans + start.charAt(i);
			else if (start.charAt(i) < end.charAt(i) && !skipflip) {
				ans = ans + start.charAt(i);
				skipflip = true;
			}

			// Flip case.
			else {
				ans = ans + end.charAt(i);
				used = true;
			}
		}

		return ans;
	}

	// Returns the distance between a and b.
	public static int distance(String a, String b) {
		int sum = 0;
		for (int i=0; i<a.length(); i++)
			if (a.charAt(i) != b.charAt(i))
				sum++;
		return sum;
	}
}

class node implements Comparable<node> {

	public String word;
	public boolean usedLink;
	public int distance;
	public String connector;
	public int index;

	public node(String myWord, int dist, int myIndex) {
		word = myWord;
		usedLink = false;
		distance = dist;
		connector = "";
		index = myIndex;
	}

	public node(String myWord, int dist, String myConnector, int myIndex) {
		word = myWord;
		usedLink = true;
		distance = dist;
		connector = myConnector;
		index = myIndex;
	}

	public int compareTo(node other) {
		if (this.distance != other.distance) return this.distance - other.distance;
		if (!this.usedLink) return -1;
		if (this.usedLink && !other.usedLink) return 1;

		// Question says to break ties this way.
		return this.connector.compareTo(other.connector);
	}

	public String toString() {
		if (usedLink) return word+","+distance+": "+connector;
		return word+","+distance;
	}
}