// Arup Guha
// 7/2/2013
// Solution to 2012 Mid-Central Regional Problem H: Bounce
import java.util.*;

public class h {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		state.numR = stdin.nextInt();

		// Go through each case.
		while (state.numR != 0) {

			// Get basic game information.
			state.numC = stdin.nextInt()+1;
			state.period = stdin.nextInt();
			state.grid = new char[state.numR*state.numC];
			Arrays.fill(state.grid,' ');

			// Read in the grid, all rows start at index 0.
			for (int i=0; i<state.numR; i++)
				for (int j=0; j<state.numC-1+i%2; j++)
					state.grid[state.numC*i+j] = stdin.next().charAt(0);

			// Output the solution.
			System.out.println(solve());

			// Get next case.
			state.numR = stdin.nextInt();
		}
	}

	public static String solve() {

		// Set up BFS, enqueue all possible starting spots on the top row.
		LinkedList<state> q = new LinkedList<state>();
		for (int i=0; i<state.numC-2; i++)
			q.offer(new state(i));

		// Go until the queue is empty.
		while (q.size() > 0) {

			// Get next queue item.
			state cur = q.poll();

			// We found a solution!
			if (cur.isSol()) return cur.pattern;

			// Put next items into the queue.
			ArrayList<state> next = cur.getNext();
			for (int i=0; i<next.size(); i++)
				q.offer(next.get(i));
		}

		// If we get here, we never found a valid path.
		return "no solution";
	}

}

class state {

	// One copy for each problem to solve.
	// Note: Store grid in one dimension...
	public static char[] grid;
	public static int numR;
	public static int numC;
	public static int period;

	// Instance variables specify a snapshot during a search.
	public long mask;
	public String pattern;
	public int last;
	public int startCol;

	// This constructor is only to start a new search.
	public state(int startpos) {
		mask = (1 << startpos);
		pattern = ""+grid[startpos];
		last = startpos;
		startCol = startpos;
	}

	// For states built from previous states.
	public state(long m, String p, int prev, int start) {
		mask = m;
		pattern = p;
		last = prev;
		startCol = start;
	}

	// Returns a list of the next possible states.
	public ArrayList<state> getNext() {

		ArrayList<state> ans = new ArrayList<state>();

		ArrayList<Integer> possible = getNextPositions();
		for (int i=0; i<possible.size(); i++) {

			// We've been to this square before.
			if ((mask & (1L << possible.get(i))) != 0) continue;

			// Restrict next letter, if necessary.
			if (pattern.length() >= period && grid[possible.get(i)] != pattern.charAt((Long.bitCount(mask)%period))) continue;

			// Add this next state.
			ans.add(new state(mask | (1L << possible.get(i)), pattern+grid[possible.get(i)], possible.get(i), startCol ));
		}

		return ans;
	}

	public boolean isSol() {

		// We didn't end on the first row.
		if (last >= numC) return false;

		// Never hit bottom row.
		if  ( (mask >> ((numR-1)*numC)) == 0) return false;

		// We can't end to the left of where we started.
		if (last < startCol) return false;

		// Needs to be a multiple (greater than 1) of the period length.
		if (Long.bitCount(mask)%period != 0 || Long.bitCount(mask) == period) return false;

		return true;
	}

	public ArrayList<Integer> getNextPositions() {

		ArrayList<Integer> list = new ArrayList<Integer>();

		// Extract last position.
		int row = last/numC;
		int col = last%numC;

		// Easier to split up work into two cases - even and odd rows.
		if (row%2 == 0) {

			// Go above.
			if (row > 0) {
				list.add((row-1)*numC+col);
				list.add((row-1)*numC+col+1);
			}

			// Same row.
			if (col > 0) list.add(row*numC+col-1);
			if (col < numC-2) list.add(row*numC+col+1);

			// Go below.
			if (row < numR-1) {
				list.add((row+1)*numC+col);
				list.add((row+1)*numC+col+1);
			}

		}

		// Odd row case. (In the problem description, this is an even row...)
		else {

			// Go above.
			if (row > 0 && col > 0)      list.add((row-1)*numC+col-1);
			if (row > 0 && col < numC-1) list.add((row-1)*numC+col);

			// Same row.
			if (col > 0) list.add(row*numC+col-1);
			if (col < numC-1) list.add(row*numC+col+1);

			// Go below.
			if (row < numR-1 && col > 0)      list.add((row+1)*numC+col-1);
			if (row < numR-1 && col < numC-1) list.add((row+1)*numC+col);
		}

		return list;
	}

}