Problem:
Problem Statement

You bought 3 ancient scrolls from a magician. These scrolls have a long string, and the lengths of the strings are the same. He said that these scrolls are copies of the key string to enter a dungeon with a secret treasure.
However, he also said, they were copied so many times by hand, so the string will contain some errors, though the length seems correct.

Your job is to recover the original string from these strings. When finding the original string, you decided to use the following assumption.

The copied string will contain at most d errors. In other words, the Hamming distance of the original string and the copied string is at most d.

If there exist many candidates, the lexicographically minimum string is the original string.

Can you find the orignal string?

Input

The input contains a series of datasets.

Each dataset has the following format:

l d
str_1
str_2
str_3

The first line contains two integers l (1 \leq l \leq 100,000) and d (0 \leq d \leq 5,000.)
l describes the length of 3 given strings and d describes acceptable maximal Hamming distance.
The following 3 lines have given strings, whose lengths are l.
These 3 strings consist of only lower and upper case alphabets.

The input ends with a line containing two zeros, which should not be processed.

Output

Print the lexicographically minimum satisfying the condition in a line.
If there do not exist such strings, print -1.

Sample Input

3 1
ACM
IBM
ICM
5 2
iwzwz
iziwi
zwizi
1 0
A
B
C
10 5
jLRNlNyGWx
yyLnlyyGDA
yLRnvyyGDA
0 0

Output for the Sample Input

ICM
iwiwi
-1
AARAlNyGDA

Solution in JAVA (judge verdict: Wrong Answer)

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int L, D;
	static char[][] str = new char[3][];
	static int[][] count;

	public static void main(String[] args) {
		while (true) {
			L = sc.nextInt();
			D = sc.nextInt();
			if (L == 0) break;
			for (int i = 0; i < 3; ++i) {
				str[i] = sc.next().toCharArray();
			}
			String ans = solve();
			System.out.println(ans == null ? "-1" : ans);
		}
	}

	static String solve() {
		count = new int[L + 1][5];
		char[] ret = new char[L];
		for (int i = 0; i < L; ++i) {
			if (str[0][i] == str[1][i] && str[0][i] == str[2][i]) {
				count[i][4]++;
			} else if (str[1][i] == str[2][i]) {
				count[i][0]++;
			} else if (str[0][i] == str[2][i]) {
				count[i][1]++;
			} else if (str[0][i] == str[1][i]) {
				count[i][2]++;
			} else {
				count[i][3]++;
			}
		}
		for (int i = L - 2; i >= 0; --i) {
			for (int j = 0; j < 5; ++j) {
				count[i][j] += count[i + 1][j];
			}
		}
		int[] rem = { D, D, D };
		for (int i = 0; i < L; ++i) {
			char[] cand = { 'A', str[0][i], str[1][i], str[2][i] };
			Arrays.sort(cand);
			boolean ok = false;
			for (char ch : cand) {
				for (int j = 0; j < 3; ++j) {
					if (str[j][i] != ch) rem[j]--;
				}
				if (ok(rem, i + 1)) {
					ok = true;
					ret[i] = ch;
					break;
				}
				for (int j = 0; j < 3; ++j) {
					if (str[j][i] != ch) rem[j]++;
				}
			}
			if (!ok) return null;
		}
		return String.valueOf(ret);
	}

	static boolean ok(int[] rem, int pos) {
		int[] num = new int[3];
		for (int i = 0; i < 3; ++i) {
			if (rem[i] < count[pos][i]) {
				num[i] += rem[i];
				for (int j = 0; j < 3; ++j) {
					if (j != i) num[j] += count[pos][i] - rem[i];
				}
			} else {
				num[i] += count[pos][i];
			}
		}
		for (int i = 0; i < 3; ++i) {
			if (num[i] > rem[i]) return false;
			num[i] = rem[i] - num[i];
		}
		Arrays.sort(num);
		int use = num[1] - num[0];
		num[1] -= use;
		num[2] -= use;
		if (num[0] + num[1] < num[2]) {
			use += num[0] + num[1];
		} else {
			use += (num[0] + num[1] + num[2]) / 2;
		}
		return count[pos][3] <= use;
	}

}