Generating Bulls and Cows secret word with given n String inputs
===

I am stuck on this problem for quite a while, it is basically reverse engineering bulls and cow game.
Read more here: http://rosettacode.org/wiki/Bulls_and_cows
I am not able to develop a logic for the problem given below, if you can think of a solving approach please comment the same.

Problem Statement: 

Given few clue words(of form ABCD/DBCA etc) and the number of cows and bulls for each word,program
should be able to work out the actual word by evaluating the given clue words and generate the output secret word.

TEST CASES: 

Input:
4 <br />
DBCC 0 2 <br />
CDAB 2 1 <br />
CAAD 1 2 <br />
CDDA 2 0 <br />

Output:
BDAA