#P6495. [COCI 2016/2017 #2] Tavan

[COCI 2016/2017 #2] Tavan

Description

Željko is reading a letter from his grandma. Because it is very old, some words in the letter can no longer be recognized. He picked a word of length nn and replaced mm unrecognizable letters with #.

For each #, grandma provided kk letters, and the original letter at that position is one of these kk letters. Among all possible words, the xx-th one in lexicographical order is the original word.

Please help them find the original word.

Input Format

The first line contains four integers n,m,k,xn,m,k,x.

The second line contains a string of length nn, representing the word Željko picked.

The next mm lines each contain a string of length kk, representing the letters provided by grandma.

Output Format

One line containing a string, representing the original word.

9 2 3 7
po#olje#i
sol
znu 
posoljeni
4 1 2 2
#rak
zm 
zrak 

Hint

Sample 1 Explanation

All possible words in lexicographical order are:

  • pololjeni
  • pololjeui
  • pololjezi
  • poooljeni
  • poooljeui
  • poooljezi
  • posoljeni
  • posoljeui
  • posoljezi

The 77-th word is posoljeni


Constraints

For 100%100\% of the testdata, 1n5001\le n\le 500, 1mn1\le m\le n, 1k261\le k\le 26, 1x1091\le x\le 10^9.

All strings contain only lowercase letters and #


Notes

This problem is translated from COCI2016-2017 CONTEST #2 T2 Tavan

Translated by ChatGPT 5