A $10\times10$ Crossword grid is provided to you, along with a set of words (or names of places) which need to be filled into the grid.  Cells are marked either + or -.  Cells marked with a - are to be filled with the word list.  

The following shows an example crossword from the input $crossword$ grid and the list of words to fit, $words=[PLAND,LHASA,SPAIN,INDIA]$:

Input 	   		Output

++++++++++ 		++++++++++
+------+++ 		+POLAND+++
+++-++++++ 		+++H++++++
+++-++++++ 		+++A++++++
+++-----++ 		+++SPAIN++
+++-++-+++ 		+++A++N+++
++++++-+++ 		++++++D+++
++++++-+++ 		++++++I+++
++++++-+++ 		++++++A+++
++++++++++ 		++++++++++
POLAND;LHASA;SPAIN;INDIA

Function Description

Complete the crosswordPuzzle function in the editor below.  It should return an array of strings, each representing a row of the finished puzzle.

crosswordPuzzle has the following parameter(s):  

crossword: an array of $10$ strings of length $10$ representing the empty grid  
words: a string consisting of semicolon delimited strings to fit into $crossword$  

Input Format

Each of the first $10$ lines represents $crossword[i]$, each of which has $10$ characters, $crossword[i][j]$.

The last line contains a string consisting of semicolon delimited $words[i]$ to fit.  

Constraints

$1\leq|words|\leq10$ 

$crossword[i][j]\in\{+,-\}$ 

$words[i][j]\in ascii[A-Z]$  

Output Format

Position the words appropriately in the $10\times10$ grid, then return your array of strings for printing.  

Sample Input 0
+-++++++++
+-++++++++
+-++++++++
+-----++++
+-+++-++++
+-+++-++++
+++++-++++
++------++
+++++-++++
+++++-++++
LONDON;DELHI;ICELAND;ANKARA

Sample Output 0
+L++++++++
+O++++++++
+N++++++++
+DELHI++++
+O+++C++++
+N+++E++++
+++++L++++
++ANKARA++
+++++N++++
+++++D++++

Sample Input 1
+-++++++++
+-++++++++
+-------++
+-++++++++
+-++++++++
+------+++
+-+++-++++
+++++-++++
+++++-++++
++++++++++
AGRA;NORWAY;ENGLAND;GWALIOR

Sample Output 1
+E++++++++
+N++++++++
+GWALIOR++
+L++++++++
+A++++++++
+NORWAY+++
+D+++G++++
+++++R++++
+++++A++++
++++++++++

Sample Input 2
++++++-+++
++------++
++++++-+++
++++++-+++
+++------+
++++++-+-+
++++++-+-+
++++++++-+
++++++++-+
++++++++-+
ICELAND;MEXICO;PANAMA;ALMATY

Sample Output 2
++++++I+++
++MEXICO++
++++++E+++
++++++L+++
+++PANAMA+
++++++N+L+
++++++D+M+
++++++++A+
++++++++T+
++++++++Y+

Difficulty: MEDIUM

Solutions:
def solve():
	board = []
	for _ in range(10):
		board.append(list(input().strip()))
	words = input().strip().split(';')
	solve_board(board, words)

def solve_board(board, words):
	word_positions = find_word_positions(board)
	word_map = generate_word_map(words)
	stack = [[]]
	while len(stack[-1]) < len(word_positions):
		current_words = stack.pop()
		possible_words = get_possible_words(current_words, word_positions, board, word_map)
		for word in possible_words:
			stack.append([w for w in current_words] + [word])
	solution = stack[-1]
	write_position(solution, word_positions, board)
	print_board(board)

def get_possible_words(current_words, word_positions, board, word_map):
	next_position = word_positions[len(current_words)]
	next_length = next_position[2]
	write_position(current_words, word_positions, board)
	possible_words = word_map[next_length].difference(set(current_words))
	possible_words = filter(lambda word: word_can_be_placed(word, next_position, board), possible_words)
	possible_words = list(possible_words)
	erase_position(current_words, word_positions, board)
	return possible_words

def word_can_be_placed(word, position, board):
	(row, col, length, direction) = position
	(row_delta, col_delta) = get_deltas(direction)
	for (char, c_row, c_col) in zip(word, (row + i * row_delta for i in range(length)), (col + i * col_delta for i in range(length))):
		if board[c_row][c_col] != '.' and board[c_row][c_col] != char:
			return False
	return True

def generate_word_map(words):
	word_map = {}
	for word in words:
		if len(word) not in word_map:
			word_map[len(word)] = set([word])
		else:
			word_map[len(word)].add(word)
	return word_map

def write_position(current_words, word_positions, board):
	for (word, position) in zip(current_words, word_positions):
		write_word(word, position, board)

def erase_position(current_words, word_positions, board):
	for (word, position) in zip(current_words, word_positions):
		erase_word(position, board)

def write_word(word, position, board):
	(row, col, length, direction) = position
	(row_delta, col_delta) = get_deltas(direction)
	for char in word:
		board[row][col] = char
		row += row_delta
		col += col_delta

def print_board(board):
	print('\n'.join(map(lambda row: ''.join(row), board)))

def find_word_positions(board):
	word_positions = []
	for i in range(len(board)):
		for j in range(len(board[0])):
			while word_starts_at(board, i, j):
				word_positions.append(precalculate_word(board, i, j))
				erase_word(word_positions[-1], board)
	return word_positions

def precalculate_word(board, i, j):
	length = 1
	if i + 1 < len(board) and board[i + 1][j] == '-':
		direction = 'DOWN'
	else:
		direction = 'ACROSS'
	(row_delta, col_delta) = get_deltas(direction)
	(row, col) = (i, j)
	while row + row_delta < len(board) and col + col_delta < len(board[0]) and (board[row + row_delta][col + col_delta] != '+'):
		row += row_delta
		col += col_delta
		length += 1
	return (i, j, length, direction)

def get_deltas(direction):
	if direction == 'DOWN':
		return (1, 0)
	else:
		return (0, 1)

def erase_word(word_position, board):
	(row, col, length, direction) = word_position
	(row_delta, col_delta) = get_deltas(direction)
	for i in range(length):
		board[row][col] = '.'
		row += row_delta
		col += col_delta

def word_starts_at(board, i, j):
	if board[i][j] == '-':
		return True
	elif board[i][j] == '.':
		if i + 1 < len(board) and board[i + 1][j] == '-':
			return True
		elif j + 1 < len(board[0]) and board[i][j + 1] == '-':
			return True
	return False
solve()


import re

def fullboard(mboard):
	for r in range(len(mboard)):
		for c in range(len(mboard[0])):
			if mboard[r][c] == '-':
				return False
	return True

def try_place(mboard, word, room):
	len_is_right = len(word) == room[3] - room[2]
	if not len_is_right:
		return (False, None)
	(kind, n, s, e) = room
	if kind == 'row':
		if not all((roomc == '-' or roomc == wordc for (wordc, roomc) in zip(word, mboard[n][s:e]))):
			return (False, None)
		saved = mboard[n][s:e]
		mboard[n][s:e] = word
	elif kind == 'col':
		if not all((roomc == '-' or roomc == wordc for (wordc, roomc) in zip(word, [mboard[i][n] for i in range(s, e)]))):
			return (False, None)
		wi = 0
		saved = tuple((mboard[i][n] for i in range(s, e)))
		for i in range(s, e):
			mboard[i][n] = word[wi]
			wi += 1
	else:
		raise Exception('invalid kind (%s), should be "row" or "col"' % kind)
	return (True, saved)

def restore(mboard, ss, room):
	assert len(room) == 4
	(kind, n, s, e) = room
	assert len(ss) == e - s
	if kind == 'row':
		mboard[n][s:e] = ss
	elif kind == 'col':
		j = 0
		for i in range(s, e):
			mboard[i][n] = ss[j]
			j += 1
	else:
		raise Exception('Invalid kind (%s), should be "row" or "col"' % kind)

def bprint(mbrd):
	for row in mbrd:
		print(''.join(row))

def place(mboard, words, rms):
	if fullboard(mboard) or len(words) == 0:
		bprint(mboard)
	else:
		assert len(rms) >= 1, 'weird, no more rooms'
		for (i, w) in enumerate(words):
			(placed_successful, saved_slice) = try_place(mboard, w, rms[0])
			if placed_successful:
				place(mboard, words[:i] + words[i + 1:], rms[1:])
				restore(mboard, saved_slice, rms[0])

def main():
	board = []
	for _ in range(11):
		board.append(input().strip())
	words = board[-1].split(';')
	del board[-1]
	assert all((10 == len(s) for s in board)), 'not all rows have 10 chars'
	assert len(board) == 10, 'not 10 rows, %d' % len(board)
	assert all((len(s) <= 10 for s in words)), 'word len must be <=10'
	assert len(words) <= 10, 'too many words, need <=10'
	mb = [list(s) for s in board]
	rooms = []
	for r in range(len(board)):
		for matchobj in re.finditer('--+', board[r]):
			rooms.append(('row', r, matchobj.span()[0], matchobj.span()[1]))
	for c in range(len(board[0])):
		vstr = ''.join((board[row][c] for row in range(len(board))))
		for matchobj in re.finditer('--+', vstr):
			rooms.append(('col', c, matchobj.span()[0], matchobj.span()[1]))
	place(mb, words, rooms)
main()


import copy
raw_board = list()
for _ in range(10):
	raw_board.append(input())
raw_words = input().split(';')

def test_board(board, words):
	buff = len(words[0])
	possible_boards = list()
	for rr in range(10):
		for cc in range(10 - buff + 1):
			if all([wl == bl or bl == '-' for (wl, bl) in zip(words[0], board[rr][cc:cc + buff])]):
				temp_board = copy.deepcopy(board)
				temp_board[rr] = temp_board[rr][:cc] + words[0] + temp_board[rr][cc + buff:]
				possible_boards.append(temp_board)
	for rr in range(10 - buff + 1):
		for cc in range(10):
			if all([wl == bl or bl == '-' for (wl, bl) in zip(words[0], [x[cc] for x in board[rr:rr + buff]])]):
				temp_board = copy.deepcopy(board)
				for ii in range(buff):
					temp_board[rr + ii] = temp_board[rr + ii][:cc] + words[0][ii] + temp_board[rr + ii][cc + 1:]
				possible_boards.append(temp_board)
	if len(words) <= 1 or not possible_boards:
		return possible_boards
	else:
		return_boards = list()
		for entry in possible_boards:
			return_boards += test_board(entry, words[1:])
		return return_boards
result = test_board(raw_board, raw_words)
for entry in result[0]:
	print(entry)


def readInts():
	return map(int, input().strip().split())

def make_sets(cs):
	rows = len(cs)
	cols = len(cs[0])
	out_sets = set()
	visited = set()
	for sr in range(rows):
		for sc in range(cols):
			if cs[sr][sc] != '-':
				continue
			if sc == 0 or cs[sr][sc - 1] != '-':
				c = sc
				while c < cols and cs[sr][c] == '-':
					visited.add((sr, c))
					c += 1
				if c - 1 > sc:
					out_sets.add(((sr, sc), c - sc, (0, 1)))
			if sr == 0 or cs[sr - 1][sc] != '-':
				r = sr
				while r < rows and cs[r][sc] == '-':
					visited.add((r, sc))
					r += 1
				if r - 1 > sr:
					out_sets.add(((sr, sc), r - sr, (1, 0)))
	return out_sets

def solve_sets(ss, ws, used):

	def addt(a, b):
		(ar, ac) = a
		(br, bc) = b
		return (ar + br, ac + bc)
	if not ws:
		return used
	w = ws.pop()
	for (src, size, dd) in ss:
		if len(w) != size:
			continue
		rc = src
		ok = True
		for d in range(size):
			if rc in used and used[rc] != w[d]:
				ok = False
				break
			rc = addt(rc, dd)
		if not ok:
			continue
		used2 = dict(used)
		rc = src
		for d in range(size):
			used2[rc] = w[d]
			rc = addt(rc, dd)
		ss2 = set(ss)
		ss2.remove((src, size, dd))
		attempt = solve_sets(ss2, ws, used2)
		if attempt:
			return attempt
	ws.append(w)
	return None
cs = [input().strip() for _ in range(10)]
ws = input().strip().split(';')
ss = make_sets(cs)
sol = solve_sets(ss, ws, dict())
rows = len(cs)
cols = len(cs[0])
for r in range(rows):
	a = []
	for c in range(cols):
		if (r, c) in sol:
			a.append(sol[r, c])
		else:
			a.append(cs[r][c])
	print(''.join(a))


from copy import deepcopy

def fill_board(board, words):
	if len(words) == 0:
		for a in board:
			for b in a:
				print(b, end='')
			print('')
	first_open_space = open_space_finder(board)
	result = word_placer(first_open_space, board, words)
	if not result:
		return False

def open_space_finder(board):
	for a in range(len(board)):
		for b in range(len(board[a])):
			if board[a][b] == '-':
				return word_finder([a, b], board)

def word_finder(open_space, board):
	word_place = []
	x = open_space[0]
	y = open_space[1]
	if x in range(1, len(board) - 1):
		if look_up(x, y, board):
			word_place.append([x - 1, y])
			word_place.append(open_space)
			return fill_down(word_place, board)
		if look_down(x, y, board):
			word_place.append(open_space)
			word_place.append([x + 1, y])
			return fill_down(word_place, board)
	elif x == 0:
		if look_down(x, y, board):
			word_place.append(open_space)
			word_place.append([x + 1, y])
			return fill_down(word_place, board)
	if y in range(1, len(board[y]) - 1):
		if look_left(x, y, board):
			word_place.append([x, y - 1])
			word_place.append(open_space)
			return fill_across(word_place, board)
		if look_right(x, y, board):
			word_place.append(open_space)
			word_place.append([x, y + 1])
			return fill_across(word_place, board)
	elif y == 0:
		if look_right(x, y, board):
			word_place.append(open_space)
			word_place.append([x, y + 1])
			return fill_across(word_place, board)

def look_up(x, y, board):
	return board[x - 1][y] != '+'

def look_down(x, y, board):
	return board[x + 1][y] != '+'

def look_left(x, y, board):
	return board[x][y - 1] != '+'

def look_right(x, y, board):
	return board[x][y + 1] != '+'

def fill_down(place_list, board):
	where_to_start = place_list[len(place_list) - 1]
	x = where_to_start[0] + 1
	y = where_to_start[1]
	while x < len(board):
		if board[x][y] != '+':
			place_list.append([x, y])
			x += 1
		else:
			x = len(board)
	return place_list

def fill_across(place_list, board):
	where_to_start = place_list[len(place_list) - 1]
	x = where_to_start[0]
	y = where_to_start[1] + 1
	while y < len(board[x]):
		if board[x][y] != '+':
			place_list.append([x, y])
			y += 1
		else:
			y = len(board[x])
	return place_list

def word_placer(place_list, board, words):
	words_that_fit = [X for X in words if len(X) == len(place_list)]
	for a in words_that_fit:
		board1 = deepcopy(board)
		words1 = deepcopy(words)
		for index in range(len(a)):
			x = place_list[index][0]
			y = place_list[index][1]
			if board[x][y] == '-':
				board1[x][y] = a[index]
			elif board[x][y] != a[index]:
				break
			if index == len(a) - 1:
				words1.remove(a)
				buzz = fill_board(board1, words1)
				break
	return False
first_board = []
for x in range(10):
	string = input()
	string_list = list(string)
	first_board.insert(x, string_list)
words = input().split(';')
fill_board(first_board, words)


w = h = 10

def find_slots(grid):
	slots = []
	for y in range(h):
		word_start = 0
		while word_start < w - 2:
			word_length = 0
			coords = []
			while True:
				x = word_start + word_length
				if x >= w or grid[y][x] != '-':
					break
				word_length += 1
				coords.append((x, y))
			if word_length >= 2:
				slots.append(coords)
			word_start += word_length + 1
	for x in range(w):
		word_start = 0
		while word_start < h - 2:
			word_length = 0
			coords = []
			while True:
				y = word_start + word_length
				if y >= h or grid[y][x] != '-':
					break
				coords.append((x, y))
				word_length += 1
			if word_length > 2:
				slots.append(coords)
			word_start += word_length + 1
	return slots

def fill(grid, slots, words_by_length):
	if not slots:
		return True
	slot = slots.pop()
	words = words_by_length[len(slot)]
	assert words
	for word in list(words):
		grid_letters = [grid[y][x] for (x, y) in slot]
		if all((grid_letter == '-' or grid_letter == word_letter for (grid_letter, word_letter) in zip(grid_letters, word))):
			for (letter, (x, y)) in zip(word, slot):
				grid[y][x] = letter
			words.remove(word)
			if fill(grid, slots, words_by_length):
				return True
			words.add(word)
			for (letter, (x, y)) in zip(grid_letters, slot):
				grid[y][x] = letter
	slots.append(slot)
	return False
grid = [list(input()) for _ in range(h)]
slots = find_slots(grid)
words = input().split(';')
words_by_length = {}
for word in words:
	words_by_length.setdefault(len(word), set()).add(word)
import sys
print(slots, file=sys.stderr)
fill(grid, slots, words_by_length)
for row in grid:
	print(''.join(row))


def print_board(board):
	for row in range(10):
		for col in range(10):
			print(board[row][col], end='')
		print('')

def find_positions(board, word):
	possibles = []
	for i in range(10):
		row = board[i]
		process_row_col(row, i, len(word), 'row', possibles)
	for j in range(10):
		col = [board[i][j] for i in range(10)]
		process_row_col(col, j, len(word), 'col', possibles)
	return possibles

def process_row_col(line, number, length, direction, possibles):
	tmp = []
	for j in range(10):
		if line[j] == '-':
			if j == 0:
				tmp.append(j)
			elif line[j - 1] == '+':
				tmp.append(j)
	for pos in tmp:
		avail = 1
		k = pos + 1
		while k < 10 and line[k] == '-':
			k += 1
			avail += 1
		if avail == length:
			if direction == 'row':
				possibles.append({'start_x': number, 'start_y': pos, 'direction': 'row'})
			else:
				possibles.append({'start_x': pos, 'start_y': number, 'direction': 'col'})

def undo(board, recovers):
	for (row, col) in recovers:
		board[row][col] = '-'

def fill_word(board, word, solution):
	row = solution['start_x']
	col = solution['start_y']
	need_recover = False
	recovers = []
	if solution['direction'] == 'row':
		for j in range(len(word)):
			if board[row][col + j] == '-':
				board[row][col + j] = word[j]
				recovers.append([row, col + j])
				j += 1
			elif board[row][col + j] == word[j]:
				j += 1
			else:
				undo(board, recovers)
				return None
	elif solution['direction'] == 'col':
		for i in range(len(word)):
			if board[row + i][col] == '-':
				board[row + i][col] = word[i]
				recovers.append([row + i, col])
				i += 1
			elif board[row + i][col] == word[i]:
				i += 1
			else:
				undo(board, recovers)
				return None
	return recovers

def fill_board(board, words, solutions):
	for (index, word) in enumerate(words):
		s_set = solutions[word]
		for s in s_set:
			recovers = fill_word(board, word, s)
			if not recovers:
				continue
			rslt = fill_board(board, words[index + 1:], solutions)
			if rslt:
				return True
			else:
				undo(board, recovers)
		else:
			return False
	return True

def main():
	board = []
	for _ in range(10):
		row = list(input().strip())
		board.append(row)
	words = [char for char in input().strip().split(';')]
	solutions = {}
	for word in words:
		possibles = find_positions(board, word)
		solutions[word] = possibles
	words = []
	for length in range(1, 11):
		for word in solutions:
			if len(solutions[word]) == length:
				words.append(word)
	fill_board(board, words, solutions)
	print_board(board)
main()


def print_board(board):
	for row in range(10):
		for col in range(10):
			print(board[row][col], end='')
		print('')

def find_positions(board, word):
	possibles = []
	for i in range(10):
		row = board[i]
		process_row_col(row, i, len(word), 'row', possibles)
	for j in range(10):
		col = [board[i][j] for i in range(10)]
		process_row_col(col, j, len(word), 'col', possibles)
	return possibles

def process_row_col(line, number, length, direction, possibles):
	tmp = []
	for j in range(10):
		if line[j] == '-':
			if j == 0:
				tmp.append(j)
			elif line[j - 1] == '+':
				tmp.append(j)
	for pos in tmp:
		avail = 1
		k = pos + 1
		while k < 10 and line[k] == '-':
			k += 1
			avail += 1
		if avail == length:
			if direction == 'row':
				possibles.append({'start_x': number, 'start_y': pos, 'direction': 'row'})
			else:
				possibles.append({'start_x': pos, 'start_y': number, 'direction': 'col'})

def undo(board, recovers):
	for (row, col) in recovers:
		board[row][col] = '-'

def fill_word(board, word, solution):
	row = solution['start_x']
	col = solution['start_y']
	need_recover = False
	recovers = []
	if solution['direction'] == 'row':
		for j in range(len(word)):
			if board[row][col + j] == '-':
				board[row][col + j] = word[j]
				recovers.append([row, col + j])
				j += 1
			elif board[row][col + j] == word[j]:
				j += 1
			else:
				undo(board, recovers)
				return None
	elif solution['direction'] == 'col':
		for i in range(len(word)):
			if board[row + i][col] == '-':
				board[row + i][col] = word[i]
				recovers.append([row + i, col])
				i += 1
			elif board[row + i][col] == word[i]:
				i += 1
			else:
				undo(board, recovers)
				return None
	return recovers

def fill_board(board, words, solutions):
	for (index, word) in enumerate(words):
		s_set = solutions[word]
		for s in s_set:
			recovers = fill_word(board, word, s)
			if not recovers:
				continue
			rslt = fill_board(board, words[index + 1:], solutions)
			if rslt:
				return True
			else:
				undo(board, recovers)
		else:
			return False
	return True

def main():
	board = []
	for _ in range(10):
		row = list(input().strip())
		board.append(row)
	words = [char for char in input().strip().split(';')]
	solutions = {}
	for word in words:
		possibles = find_positions(board, word)
		solutions[word] = possibles
	words = []
	for length in range(1, 11):
		for word in solutions:
			if len(solutions[word]) == length:
				words.append(word)
	fill_board(board, words, solutions)
	print_board(board)
main()


import sys

def getLength(array, x, y, orientation):
	length = 0
	if orientation == 'vertical':
		while y < 10 and array[y][x] == '-':
			length += 1
			y += 1
	elif orientation == 'horizontal':
		while x < 10 and array[y][x] == '-':
			length += 1
			x += 1
	return length
array = []
for i in range(10):
	array.append(list(input().strip()))
words = input().strip().split(';')
spaces = []
for y in range(10):
	for x in range(10):
		if y < 9 and array[y][x] == '-' and (array[y + 1][x] == '-'):
			if y > 0 and array[y - 1][x] == '+' or y == 0:
				length = getLength(array, x, y, 'vertical')
				spaces.append({'length': length, 'x': x, 'y': y, 'orientation': 'vertical'})
		if x < 9 and array[y][x] == '-' and (array[y][x + 1] == '-'):
			if x > 0 and array[y][x - 1] == '+' or x == 0:
				length = getLength(array, x, y, 'horizontal')
				spaces.append({'length': length, 'x': x, 'y': y, 'orientation': 'horizontal'})

def setWord(array, crossword):
	if crossword['orientation'] == 'horizontal':
		for x in range(crossword['x'], crossword['x'] + crossword['length']):
			if array[crossword['y']][x] != '-' and array[crossword['y']][x] != crossword['word'][x - crossword['x']]:
				return False
			array[crossword['y']][x] = crossword['word'][x - crossword['x']]
	elif crossword['orientation'] == 'vertical':
		for y in range(crossword['y'], crossword['y'] + crossword['length']):
			if array[y][crossword['x']] != '-' and array[y][crossword['x']] != crossword['word'][y - crossword['y']]:
				return False
			array[y][crossword['x']] = crossword['word'][y - crossword['y']]

def recSetWord(spaces, words, crosswords):
	if spaces == []:
		newArray = [line.copy() for line in array]
		for crossword in crosswords:
			if setWord(newArray, crossword) == False:
				return
		print('\n'.join(map(str, [''.join(map(str, line)) for line in newArray])) + '\n')
		return
	space = spaces[0].copy()
	for word in range(len(words)):
		if len(words[word]) == space['length']:
			space['word'] = words[word]
			recSetWord(spaces[1:], [newWord for newWord in words if newWord != words[word]], crosswords[:] + [space])
setCount = 0
recSetWord(spaces, words, [])


g = [list(input()) for _ in range(10)]
words = input().split(';')

def solve(g, words, index):
	if index == len(words):
		return g
	word = words[index]
	for i in range(10):
		for j in range(10):
			if g[i][j] == '-' or g[i][j] == word[0]:
				for k in range(len(word)):
					if j + k >= 10 or g[i][j + k] not in ('-', word[k]):
						break
				else:
					g2 = [l[:] for l in g]
					for k in range(len(word)):
						g2[i][j + k] = word[k]
					res = solve(g2, words, index + 1)
					if res:
						return res
				for k in range(len(word)):
					if i + k >= 10 or g[i + k][j] not in ('-', word[k]):
						break
				else:
					g2 = [l[:] for l in g]
					for k in range(len(word)):
						g2[i + k][j] = word[k]
					res = solve(g2, words, index + 1)
					if res:
						return res
print('\n'.join((''.join(l) for l in solve(g, words, 0))))


from collections import defaultdict
from itertools import permutations
import copy
board = [[c for c in input()] for _ in range(10)]
words = defaultdict(list)
for w in input().split(';'):
	words[len(w)].append(w)
hor_words = list()
ver_words = list()
y = 0
for r in board:
	start = 0
	end = 0
	for c in r:
		if c == '-':
			end += 1
		else:
			if end - start > 1:
				hor_words.append([start, y, end - start])
			end += 1
			start = end
	if end - start > 1:
		hor_words.append([start, y, end - start])
	y += 1
x = 0
for y in range(10):
	start = 0
	end = 0
	col = ''.join([c[x] for c in board])
	for c in col:
		if c == '-':
			end += 1
		else:
			if end - start > 1:
				ver_words.append([x, start, end - start])
			end += 1
			start = end
	if end - start > 1:
		ver_words.append([x, start, end - start])
	x += 1

def write_horizontal(board, x, y, w):
	for (i, c) in enumerate(w):
		if board[y][x + i] != '-' and board[y][x + i] != c:
			raise IndexError()
		board[y][x + i] = c

def write_vertical(board, x, y, w):
	for (i, c) in enumerate(w):
		if board[y + i][x] != '-' and board[y + i][x] != c:
			raise IndexError()
		board[y + i][x] = c
for (l, v) in [(k, v) for (k, v) in words.items() if len(v) == 1]:
	for pos in hor_words:
		if pos[2] == l:
			write_horizontal(board, pos[0], pos[1], v[0])
	for pos in ver_words:
		if pos[2] == l:
			write_vertical(board, pos[0], pos[1], v[0])
tmp = list()
for (k, v) in words.items():
	if len(v) != 1:
		tmp.extend(v)
words = tmp
for solution in permutations(words):
	try:
		sol = copy.deepcopy(board)
		sol_hor = copy.deepcopy(hor_words)
		sol_ver = copy.deepcopy(ver_words)
		for w in solution:
			added = False
			for pos in sol_hor:
				if pos[2] == len(w):
					sol_hor.remove(pos)
					write_horizontal(sol, pos[0], pos[1], w)
					added = True
					break
			if not added:
				for pos in sol_ver:
					if pos[2] == len(w):
						sol_ver.remove(pos)
						write_vertical(sol, pos[0], pos[1], w)
						break
		board = sol
		break
	except IndexError:
		pass
print('\n'.join([''.join(c) for c in board]))


import itertools
A = [input() for i in range(10)]
(horizontal, vertical) = ([], [])
for lst in (horizontal, vertical):
	for row in range(10):
		for (c, g) in itertools.groupby(range(10), key=lambda x: A[row][x]):
			l = list(g)
			if c == '-' and len(l) > 1:
				lst.append([row, l[0], l[-1]])
	A = list(map(list, zip(*A)))
intersections = [(i, column[0] - row[1], j, row[0] - column[1]) for (i, row) in enumerate(horizontal) for (j, column) in enumerate(vertical) if row[1] <= column[0] <= row[2] and column[1] <= row[0] <= column[2]]
words = input().split(';')
result = None
for l in itertools.permutations(words, len(words)):
	if all((len(l[i]) == horizontal[i][2] - horizontal[i][1] + 1 for i in range(len(horizontal)))) and all((len(l[i + len(horizontal)]) == vertical[i][2] - vertical[i][1] + 1 for i in range(len(vertical)))) and all((l[i[0]][i[1]] == l[i[2] + len(horizontal)][i[3]] for i in intersections)):
		result = l
		break
for (i, x) in enumerate(horizontal):
	A[x[0]][x[1]:x[2] + 1] = result[i]
A = list(map(list, zip(*A)))
for (i, x) in enumerate(vertical):
	A[x[0]][x[1]:x[2] + 1] = result[i + len(horizontal)]
A = list(map(list, zip(*A)))
print(*(''.join(x) for x in A), sep='\n')


def next_cell(board, cell_index, change):
	(i, j) = cell_index
	(x, y) = change
	(i, j) = (i + x, y + j)
	if 0 <= i < len(board) and 0 <= j < len(board[i]) and board[i][j]:
		return (i, j)

def read_word(board, cell_index, change):
	word = []
	while cell_index is not None:
		word.append(cell_index)
		cell_index = next_cell(board, cell_index, change)
	return word

def read_board(board):
	down = dict()
	free_words = []
	word_index = 0
	for i in range(len(board)):
		for j in range(len(board[i])):
			cell = board[i][j]
			cell_index = (i, j)
			if cell:
				if cell_index not in down:
					word = read_word(board, cell_index, (0, 1))
					if len(word) > 1:
						free_words.append((cell_index, len(word)))
						for (index, word_cell_index) in enumerate(word):
							down[word_cell_index] = (word_index, index)
						word_index += 1
	right = set()
	restrict_words = []
	for i in range(len(board)):
		for j in range(len(board[i])):
			cell = board[i][j]
			cell_index = (i, j)
			if cell:
				if cell_index not in right:
					word = read_word(board, cell_index, (1, 0))
					if len(word) > 1:
						restricts = []
						for (letter_index, word_cell_index) in enumerate(word):
							right.add(word_cell_index)
							if word_cell_index in down:
								restricts.append((letter_index, down[word_cell_index]))
						restrict_words.append((cell_index, len(word), restricts))
	return (restrict_words, free_words)

def fill(board, cell, word, change):
	(i, j) = cell
	(x, y) = change
	for letter in word:
		board[i][j] = letter
		i += x
		j += y

def pop_board(board, down, right):
	for (cell, word) in down:
		fill(board, cell, word, (0, 1))
	for (cell, word) in right:
		fill(board, cell, word, (1, 0))

def find_sol(restricts, free, words, sol=None, used=None, free_index=0, restrict_index=0):
	if used is None:
		used = dict()
		for word in words:
			used[word] = False
	if sol is None:
		sol = []
	if len(sol) == len(words):
		return sol
	if len(sol) < len(free):
		(start, size) = free[free_index]
		for word in words:
			if not used[word] and len(word) == size:
				used[word] = True
				sol.append((start, word))
				ret = find_sol(restricts, free, words, sol, used, free_index + 1, restrict_index)
				if ret is not None:
					return ret
				sol.pop()
				used[word] = False
	else:
		(start, size, rests) = restricts[restrict_index]
		for word in words:
			if not used[word] and len(word) == size:
				rests_win = False
				for (home_index, (word_index, letter_index)) in rests:
					rival = sol[word_index][1]
					if word[home_index] != rival[letter_index]:
						rests_win = True
				if rests_win:
					continue
				used[word] = True
				sol.append((start, word))
				ret = find_sol(restricts, free, words, sol, used, free_index, restrict_index + 1)
				if ret is not None:
					return ret
				sol.pop()
				used[word] = False

def main():
	board = [[False] * 10 for _ in range(10)]
	raw_board = []
	for i in range(10):
		line = input()
		raw_board.append(list(line))
		for (j, l) in enumerate(line):
			if l == '-':
				board[i][j] = True
	words = input().strip().split(';')
	(rests, free) = read_board(board)
	sol = find_sol(rests, free, words)
	down = sol[:len(free)]
	right = sol[len(free):]
	pop_board(raw_board, down, right)
	for line in raw_board:
		print(''.join(line))
main()


import itertools
A = [input() for i in range(10)]
(horizontal, vertical) = ([], [])
for lst in (horizontal, vertical):
	for row in range(10):
		for (c, g) in itertools.groupby(range(10), key=lambda x: A[row][x]):
			l = list(g)
			if c == '-' and len(l) > 1:
				lst.append([row, l[0], l[-1]])
	A = list(map(list, zip(*A)))
intersections = [(i, column[0] - row[1], j, row[0] - column[1]) for (i, row) in enumerate(horizontal) for (j, column) in enumerate(vertical) if row[1] <= column[0] <= row[2] and column[1] <= row[0] <= column[2]]
words = input().split(';')
result = None
for l in itertools.permutations(words, len(words)):
	if all((len(l[i]) == horizontal[i][2] - horizontal[i][1] + 1 for i in range(len(horizontal)))) and all((len(l[i + len(horizontal)]) == vertical[i][2] - vertical[i][1] + 1 for i in range(len(vertical)))) and all((l[i[0]][i[1]] == l[i[2] + len(horizontal)][i[3]] for i in intersections)):
		result = l
		break
for (i, x) in enumerate(horizontal):
	A[x[0]][x[1]:x[2] + 1] = result[i]
A = list(map(list, zip(*A)))
for (i, x) in enumerate(vertical):
	A[x[0]][x[1]:x[2] + 1] = result[i + len(horizontal)]
A = list(map(list, zip(*A)))
print(*(''.join(x) for x in A), sep='\n')


class WordSlot:

	def __init__(self, row, col, length, is_horiz):
		self.row = row
		self.col = col
		self.length = length
		self.is_horiz = is_horiz
		self.word = None

	def fill(self, word, board):
		curr_row = self.row
		curr_col = self.col
		if len(word) != self.length or not self.word is None:
			return False
		for i in range(len(word)):
			c = word[i]
			c_board = board[curr_row][curr_col]
			if c != c_board and c_board != '-':
				return False
			if self.is_horiz:
				curr_col = curr_col + 1
			else:
				curr_row = curr_row + 1
		curr_row = self.row
		curr_col = self.col
		for i in range(len(word)):
			c = word[i]
			board[curr_row][curr_col] = c
			if self.is_horiz:
				curr_col = curr_col + 1
			else:
				curr_row = curr_row + 1
		self.word = word
		return True

	def clear(self, board):
		self.word = None
		curr_row = self.row
		curr_col = self.col
		for i in range(self.length):
			board[curr_row][curr_col] = '-'
			if self.is_horiz:
				curr_col = curr_col + 1
			else:
				curr_row = curr_row + 1

def get_wordslots(board, words):
	ret = []
	for row in range(len(board)):
		if len(ret) == len(words):
			break
		cols = board[row]
		for col in range(len(cols)):
			c = board[row][col]
			if c == '-':
				is_vert_start = (row == 0 or board[row - 1][col] != '-') and (row < len(board) - 1 and board[row + 1][col] == '-')
				is_horiz_start = col == 0 or (board[row][col - 1] != '-' and (col < len(cols) - 1 and board[row][col + 1] == '-'))
				if is_vert_start or is_horiz_start:
					curr_row = row
					curr_col = col
					length = 0
					c = board[curr_row][curr_col]
					while c == '-':
						length += 1
						if is_horiz_start:
							curr_col += 1
						else:
							curr_row += 1
						if not curr_row < len(board) or not curr_col < len(cols):
							break
						c = board[curr_row][curr_col]
					wordslot = WordSlot(row, col, length, is_horiz_start)
					ret.append(wordslot)
	return ret

def recurse(wordslots, words, board):
	if len(words) == 0:
		return True
	word = words[-1]
	for wordslot in wordslots:
		if wordslot.fill(word, board):
			remaining_wordslots = wordslots
			remaining_words = list(words)
			remaining_words.pop()
			is_solved = recurse(remaining_wordslots, remaining_words, board)
			if is_solved:
				return True
			else:
				wordslot.clear(board)
	return False

def solve_board(board, words):
	wordslots = get_wordslots(board, words)
	recurse(wordslots, words, board)
	print_board(board)

def print_board(board):
	for row_a in board:
		row_str = ''
		for row_c in row_a:
			row_str += row_c
		print(row_str)
board = []
for i in range(10):
	row = list(input().strip())
	board.append(row)
words = list(input().strip().split(';'))
solve_board(board, words)


import itertools
A = [input() for i in range(10)]
(horizontal, vertical) = ([], [])
for lst in (horizontal, vertical):
	for row in range(10):
		for (c, g) in itertools.groupby(range(10), key=lambda x: A[row][x]):
			l = list(g)
			if c == '-' and len(l) > 1:
				lst.append([row, l[0], l[-1]])
	A = list(map(list, zip(*A)))
intersections = [(i, column[0] - row[1], j, row[0] - column[1]) for (i, row) in enumerate(horizontal) for (j, column) in enumerate(vertical) if row[1] <= column[0] <= row[2] and column[1] <= row[0] <= column[2]]
words = input().split(';')
result = None
for l in itertools.permutations(words, len(words)):
	if all((len(l[i]) == horizontal[i][2] - horizontal[i][1] + 1 for i in range(len(horizontal)))) and all((len(l[i + len(horizontal)]) == vertical[i][2] - vertical[i][1] + 1 for i in range(len(vertical)))) and all((l[i[0]][i[1]] == l[i[2] + len(horizontal)][i[3]] for i in intersections)):
		result = l
		break
for (i, x) in enumerate(horizontal):
	A[x[0]][x[1]:x[2] + 1] = result[i]
A = list(map(list, zip(*A)))
for (i, x) in enumerate(vertical):
	A[x[0]][x[1]:x[2] + 1] = result[i + len(horizontal)]
A = list(map(list, zip(*A)))
print(*(''.join(x) for x in A), sep='\n')


import re

class Slot:

	def __init__(self, start, length, vertical, taken):
		self.start = start
		self.length = length
		self.vertical = vertical
		self.taken = taken

def main():
	(grid, slots) = read_grid()
	words = input().split(';')
	solve_puzzle(grid, slots, words)
	for row in grid:
		print(''.join(row))

def read_grid():
	rows = []
	for i in range(10):
		row = input()
		rows.append(row)
	row_slots = find_slots(rows)
	cols = []
	for i in range(10):
		col = ''
		for j in range(10):
			col += rows[j][i]
		cols.append(col)
	col_slots = find_slots(cols, vertical=True)
	return ([list(row) for row in rows], row_slots + col_slots)

def find_slots(lines, vertical=False):
	slots = []
	i = 0
	for line in lines:
		for slot in line.split('+'):
			if len(slot) > 1:
				for m in re.finditer(slot, line):
					if vertical:
						start = (m.start(), i)
					else:
						start = (i, m.start())
					slots.append(Slot(start, m.end() - m.start(), vertical, False))
		i += 1
	return slots

def solve_puzzle(grid, slots, words):
	if is_complete(slots):
		return True
	for word in words:
		for slot in slots:
			if not slot.taken and len(word) == slot.length:
				(before, succeed) = add(grid, slot, word)
				if succeed:
					slot.taken = True
					complete = solve_puzzle(grid, slots, words)
					if complete:
						return True
				add(grid, slot, before, revert=True)
				slot.taken = False
	return False

def add(grid, slot, word, revert=False):
	before = []
	(row, col) = slot.start
	for c in word:
		if not revert and grid[row][col] != '-' and (grid[row][col] != c):
			return (before, False)
		before.append(grid[row][col])
		grid[row][col] = c
		if slot.vertical:
			row += 1
		else:
			col += 1
	return (before, True)

def is_complete(slots):
	for slot in slots:
		if slot.taken == False:
			return False
	return True
main()


i_grid = [input().strip() for _ in range(10)]
i_names = input().strip().split(';')

def recu(grid, names):
	if len(names) == 0:
		return (True, grid, names)
	name = names.pop()
	for (xness, yness) in [(0, 1), (1, 0)]:
		for y in range(10):
			for x in range(10):
				possible = True
				if x + xness * len(name) > 10 or y + yness * len(name) > 10:
					possible = False
					continue
				for lett in range(0, len(name)):
					if not (grid[y + yness * lett][x + xness * lett] == '-' or grid[y + yness * lett][x + xness * lett] == name[lett]):
						possible = False
				if possible:
					ngrid = []
					for row in grid:
						ngrid.append(row)
					nnames = []
					for item in names:
						nnames.append(item)
					for ltt in range(0, len(name)):
						(xco, yco) = (x + xness * ltt, y + yness * ltt)
						ngrid[yco] = ngrid[yco][:xco] + name[ltt] + ngrid[yco][xco + 1:]
					(solved, gr, na) = recu(ngrid, nnames)
					if solved:
						return (solved, gr, na)
	return (False, None, None)

def caller():
	(solved, gr, na) = recu(i_grid, i_names)
	for line in gr:
		print(line)
caller()


import sys
input_grid = []
for i in range(10):
	new_line = []
	for i in input():
		if i == '-':
			new_line.append(0)
		else:
			new_line.append(1)
	input_grid.append(new_line)
word_list = input().split(';')

def find_next_available(input_grid):
	for i in range(10):
		for j in range(10):
			if input_grid[i][j] == 0:
				return (i, j)
	return (-1, -1)

def valid_position(grid, i, j, word, horizontally=False):
	if horizontally:
		if j + len(word) - 1 >= 10:
			return False
		for k in range(len(word)):
			if grid[i][j + k] == 1:
				return False
			if grid[i][j + k] != 0:
				if grid[i][j + k][0] != word[k]:
					return False
		return True
	else:
		if i + len(word) - 1 >= 10:
			return False
		for k in range(len(word)):
			if grid[i + k][j] == 1:
				return False
			if grid[i + k][j] != 0:
				if grid[i + k][j][0] != word[k]:
					return False
		return True

def fill(grid, i, j, word, horizontally=False):
	if horizontally:
		for k in range(len(word)):
			if grid[i][j + k] == 0:
				grid[i][j + k] = (word[k], 0)
			grid[i][j + k] = (grid[i][j + k][0], grid[i][j + k][1] + 1)
	else:
		for k in range(len(word)):
			if grid[i + k][j] == 0:
				grid[i + k][j] = (word[k], 0)
			grid[i + k][j] = (grid[i + k][j][0], grid[i + k][j][1] + 1)

def unfill(grid, i, j, word, horizontally=False):
	if horizontally:
		for k in range(len(word)):
			grid[i][j + k] = (grid[i][j + k][0], grid[i][j + k][1] - 1)
			if grid[i][j + k][1] == 0:
				grid[i][j + k] = 0
	else:
		for k in range(len(word)):
			grid[i + k][j] = (grid[i + k][j][0], grid[i + k][j][1] - 1)
			if grid[i + k][j][1] == 0:
				grid[i + k][j] = 0

def pretty_print(grid):
	for i in range(10):
		new_line = ''
		for char in grid[i]:
			if char == 1:
				new_line += '+'
			elif char == 0:
				new_line += '-'
			else:
				new_line += char[0]
		print(new_line)
	print('\n')

def crosspuzzle(input_grid, word_list, i=0, j=0):
	(i, j) = find_next_available(input_grid)
	if i == -1:
		return True
	for w in range(len(word_list)):
		if valid_position(input_grid, i, j, word_list[w]):
			fill(input_grid, i, j, word_list[w])
			new_word_list = word_list[:w] + word_list[w + 1:]
			if crosspuzzle(input_grid, new_word_list, i, j):
				return True
			unfill(input_grid, i, j, word_list[w])
		if i - 1 >= 0:
			i_new = i - 1
			if valid_position(input_grid, i_new, j, word_list[w]):
				fill(input_grid, i_new, j, word_list[w])
				new_word_list = word_list[:w] + word_list[w + 1:]
				if crosspuzzle(input_grid, new_word_list, i_new, j):
					return True
				unfill(input_grid, i_new, j, word_list[w])
		if valid_position(input_grid, i, j, word_list[w], True):
			fill(input_grid, i, j, word_list[w], True)
			new_word_list = word_list[:w] + word_list[w + 1:]
			if crosspuzzle(input_grid, new_word_list, i, j):
				return True
			unfill(input_grid, i, j, word_list[w], True)
		if j - 1 > 0:
			if valid_position(input_grid, i, j - 1, word_list[w], True):
				fill(input_grid, i, j - 1, word_list[w], True)
				new_word_list = word_list[:w] + word_list[w + 1:]
				if crosspuzzle(input_grid, new_word_list, i, j - 1):
					return True
				unfill(input_grid, i, j - 1, word_list[w], True)
	return False

def solve(input_grid, word_list):
	crosspuzzle(input_grid, word_list)
	pretty_print(input_grid)
solve(input_grid, word_list)


class Slot:

	def __init__(self, start, length, vertical, taken):
		self.start = start
		self.length = length
		self.vertical = vertical
		self.taken = taken

def main():
	(grid, slots) = read_grid()
	words = set(input().split(';'))
	solve_puzzle(grid, slots, words)
	for row in grid:
		print(''.join(row))

def read_grid():
	rows = []
	for i in range(10):
		row = input()
		rows.append(row)
	row_slots = _get_slots(rows)
	cols = []
	for i in range(10):
		col = ''
		for j in range(10):
			col += rows[j][i]
		cols.append(col)
	col_slots = _get_slots(cols, vertical=True)
	return ([list(row) for row in rows], row_slots + col_slots)

def _get_slots(lines, vertical=False):
	slots = []
	line_num = 0
	for line in lines:
		for occurrence in _slot_occurrences(line):
			(slot_index, slot_length) = occurrence
			if vertical:
				start = (slot_index, line_num)
			else:
				start = (line_num, slot_index)
			slots.append(Slot(start, slot_length, vertical, False))
		line_num += 1
	return slots

def _slot_occurrences(line):
	slots = []
	for slot in line.split('+'):
		slot_length = len(slot)
		if slot_length > 1:
			index = 0
			while index < slot_length:
				index = line.find(slot, index)
				if line == -1:
					break
				slots.append((index, slot_length))
				index += slot_length
	return slots

def solve_puzzle(grid, slots, words):
	if len(words) == 0:
		return True
	for word in words:
		for slot in slots:
			if _can_add(grid, slot, word):
				before = _add(grid, slot, word)
				slot.taken = True
				new_words = set(words)
				new_words.remove(word)
				if solve_puzzle(grid, slots, new_words):
					return True
				_add(grid, slot, before)
				slot.taken = False
	return False

def _can_add(grid, slot, word):
	if slot.taken or len(word) != slot.length:
		return False
	(row, col) = slot.start
	for c in word:
		if not (grid[row][col] == '-' or grid[row][col] == c):
			return False
		(row, col) = _next(row, col, slot.vertical)
	return True

def _add(grid, slot, word):
	before = []
	(row, col) = slot.start
	for c in word:
		before.append(grid[row][col])
		grid[row][col] = c
		(row, col) = _next(row, col, slot.vertical)
	return before

def _next(row, col, vertical):
	if vertical:
		return (row + 1, col)
	else:
		return (row, col + 1)
main()


def solveCrossword(grid, n, cities, starts, intersections):
	if len(cities) == 0:
		return True
	for p in range(2):
		for city in cities:
			if willCityFitInThisRow(grid, n, city, starts):
				updateCityInThisRow(grid, n, city, starts)
				taken_city = city
				taken_start = starts.pop(0)
				cities.remove(city)
				if solveCrossword(grid, n, cities, starts, intersections):
					return True
				starts.insert(0, taken_start)
				cities.append(taken_city)
				rollback(grid, n, city, starts, 'row', intersections)
			if willCityFitInThisCol(grid, n, city, starts):
				updateCityInThisCol(grid, n, city, starts)
				taken_city = city
				taken_start = starts.pop(0)
				cities.remove(city)
				if solveCrossword(grid, n, cities, starts, intersections):
					return True
				starts.insert(0, taken_start)
				cities.append(taken_city)
				rollback(grid, n, city, starts, 'col', intersections)
	return False

def computeStarts(grid, n):
	starts = []
	for i in range(n):
		for j in range(n):
			if isStart(grid, n, i, j):
				starts.append((i, j))
	return starts

def computeIntersection(grid, n):
	intersections = []
	for i in range(n):
		for j in range(n):
			if isIntersection(grid, n, i, j):
				intersections.append((i, j))
	return intersections

def isStart(grid, n, i, j):
	if isFreeSlot(grid, n, i, j):
		if (j - 1 >= 0 and grid[i][j - 1] == '+' or j - 1 < 0) and j + 1 < n and isFreeSlot(grid, n, i, j + 1):
			return True
		if (i - 1 >= 0 and grid[i - 1][j] == '+' or i - 1 < 0) and i + 1 < n and isFreeSlot(grid, n, i + 1, j):
			return True
	return False

def willCityFitInThisRow(grid, n, city, starts):
	(i, j) = starts[0]
	for row in range(len(city)):
		if not isFreeSlot(grid, n, i, j + row):
			return False
	for (row, s) in enumerate(city):
		if 'A' <= grid[i][j + row] <= 'Z' and grid[i][j + row] != s:
			return False
	nextToLast = len(city) + j
	if nextToLast < n and isFreeSlot(grid, n, i, nextToLast):
		return False
	return True

def willCityFitInThisCol(grid, n, city, starts):
	(i, j) = starts[0]
	for col in range(len(city)):
		if not isFreeSlot(grid, n, i + col, j):
			return False
	for (col, s) in enumerate(city):
		if 'A' <= grid[i + col][j] <= 'Z' and grid[i + col][j] != s:
			return False
	nextToLast = len(city) + i
	if nextToLast < n and isFreeSlot(grid, n, nextToLast, j):
		return False
	return True

def updateCityInThisRow(grid, n, city, starts):
	(i, j) = starts[0]
	for (row, s) in enumerate(city):
		grid[i][j + row] = s

def updateCityInThisCol(grid, n, city, starts):
	(i, j) = starts[0]
	for (col, s) in enumerate(city):
		grid[i + col][j] = s

def isFreeSlot(grid, n, x, y):
	if 0 <= x < n and 0 <= y < n:
		if grid[x][y] == '-' or 'A' <= grid[x][y] <= 'Z':
			return True
	return False

def isIntersection(grid, n, x, y):
	leftRightAllowed = topBottomAllowed = False
	if not isFreeSlot(grid, n, x, y):
		return False
	if x + 1 < n and isFreeSlot(grid, n, x + 1, y) or (x - 1 >= 0 and isFreeSlot(grid, n, x - 1, y)):
		leftRightAllowed = True
	if y + 1 < n and isFreeSlot(grid, n, x, y + 1) or (y - 1 >= 0 and isFreeSlot(grid, n, x, y - 1)):
		topBottomAllowed = True
	return leftRightAllowed and topBottomAllowed

def rollback(grid, n, city, starts, orientation, intersections):
	(i, j) = starts[0]
	if orientation == 'row':
		for row in range(len(city)):
			grid[i][j + row] = '-'
		return True
	if orientation == 'col':
		for col in range(len(city)):
			grid[i + col][j] = '-'
		return True

def printCrossword(grid, n):
	for i in range(n):
		for j in range(n):
			print(grid[i][j], sep='', end='')
		print()
n = 10
grid = [['+'] * n for i in range(n)]
for i in range(n):
	grid[i] = list(input().strip())
cities = [city for city in input().strip().split(';')]
starts = computeStarts(grid, n)
intersections = computeIntersection(grid, n)
solveCrossword(grid, n, cities, starts, intersections)
printCrossword(grid, n)


import copy
board = []
for i in range(10):
	board.append(list(input().strip()))
w = input().strip().split(';')

def solve(b, words):
	if False:
		for ii in b:
			print(''.join(ii))
		print('')
	bt = [list(z) for z in zip(*b)]
	L = len(words[0])
	for k in range(10):
		for i in range(10 - L + 1):
			match = True
			for j in range(L):
				if not (b[k][i + j] == '-') | (b[k][i + j] == words[0][j]):
					match = False
					break
			if i != 0:
				if b[k][i - 1] == '-':
					match = False
			if i + L + 1 < 10:
				if b[k][i + L + 1] == '-':
					match = False
			if match:
				bcopy = copy.deepcopy(b)
				bcopy[k] = b[k][:i] + list(words[0]) + b[k][i + L:]
				if len(words) == 1:
					return bcopy
				else:
					bprime = solve(bcopy, words[1:])
					if bprime != None:
						return bprime
			match = True
			for j in range(L):
				if not (bt[k][i + j] == '-') | (bt[k][i + j] == words[0][j]):
					match = False
					break
			if i != 0:
				if bt[k][i - 1] == '-':
					match = False
			if i + L + 1 < 10:
				if bt[k][i + L + 1] == '-':
					match = False
			if match:
				btcopy = copy.deepcopy(bt)
				btcopy[k] = bt[k][:i] + list(words[0]) + bt[k][i + L:]
				btt = [list(z) for z in zip(*btcopy)]
				if len(words) == 1:
					return btt
				else:
					bprime = solve(btt, words[1:])
					if bprime != None:
						return bprime
	return None
solution = solve(board, w)
if solution == None:
	print('Oops, didnt find a solution!')
else:
	for i in solution:
		print(''.join(i))


class Slot:

	def __init__(self, start, length, vertical, taken):
		self.start = start
		self.length = length
		self.vertical = vertical
		self.taken = taken

def main():
	(grid, slots) = read_grid()
	words = set(input().split(';'))
	solve_puzzle(grid, slots, words)
	for row in grid:
		print(''.join(row))

def read_grid():
	rows = []
	for i in range(10):
		row = input()
		rows.append(row)
	row_slots = _get_slots(rows)
	cols = []
	for i in range(10):
		col = ''
		for j in range(10):
			col += rows[j][i]
		cols.append(col)
	col_slots = _get_slots(cols, vertical=True)
	return ([list(row) for row in rows], row_slots + col_slots)

def _get_slots(lines, vertical=False):
	slots = []
	line_num = 0
	for line in lines:
		for occurrence in _slot_occurrences(line):
			(slot_index, slot_length) = occurrence
			if vertical:
				start = (slot_index, line_num)
			else:
				start = (line_num, slot_index)
			slots.append(Slot(start, slot_length, vertical, False))
		line_num += 1
	return slots

def _slot_occurrences(line):
	slots = []
	for slot in line.split('+'):
		slot_length = len(slot)
		if slot_length > 1:
			index = 0
			while index < slot_length:
				index = line.find(slot, index)
				if line == -1:
					break
				slots.append((index, slot_length))
				index += slot_length
	return slots

def solve_puzzle(grid, slots, words):
	if len(words) == 0:
		return True
	for word in words:
		for slot in slots:
			if _can_add(grid, slot, word):
				before = _add(grid, slot, word)
				slot.taken = True
				new_words = set(words)
				new_words.remove(word)
				if solve_puzzle(grid, slots, new_words):
					return True
				_add(grid, slot, before)
				slot.taken = False
	return False

def _can_add(grid, slot, word):
	if slot.taken or len(word) != slot.length:
		return False
	(row, col) = slot.start
	for c in word:
		if not (grid[row][col] == '-' or grid[row][col] == c):
			return False
		(row, col) = _next(row, col, slot.vertical)
	return True

def _add(grid, slot, word):
	before = []
	(row, col) = slot.start
	for c in word:
		before.append(grid[row][col])
		grid[row][col] = c
		(row, col) = _next(row, col, slot.vertical)
	return before

def _next(row, col, vertical):
	if vertical:
		return (row + 1, col)
	else:
		return (row, col + 1)
main()


import itertools
A = [input() for i in range(10)]
(horizontal, vertical) = ([], [])
for lst in (horizontal, vertical):
	for row in range(10):
		for (c, g) in itertools.groupby(range(10), key=lambda x: A[row][x]):
			l = list(g)
			if c == '-' and len(l) > 1:
				lst.append([row, l[0], l[-1]])
	A = list(map(list, zip(*A)))
intersections = [(i, column[0] - row[1], j, row[0] - column[1]) for (i, row) in enumerate(horizontal) for (j, column) in enumerate(vertical) if row[1] <= column[0] <= row[2] and column[1] <= row[0] <= column[2]]
words = input().split(';')
result = None
for l in itertools.permutations(words, len(words)):
	if all((len(l[i]) == horizontal[i][2] - horizontal[i][1] + 1 for i in range(len(horizontal)))) and all((len(l[i + len(horizontal)]) == vertical[i][2] - vertical[i][1] + 1 for i in range(len(vertical)))) and all((l[i[0]][i[1]] == l[i[2] + len(horizontal)][i[3]] for i in intersections)):
		result = l
		break
for (i, x) in enumerate(horizontal):
	A[x[0]][x[1]:x[2] + 1] = result[i]
A = list(map(list, zip(*A)))
for (i, x) in enumerate(vertical):
	A[x[0]][x[1]:x[2] + 1] = result[i + len(horizontal)]
A = list(map(list, zip(*A)))
print(*(''.join(x) for x in A), sep='\n')


maxrow = 10
maxcol = 10

def solve(puzzle, words):
	if len(words) == 0:
		return puzzle
	for row in range(maxrow):
		for col in range(maxcol):
			if puzzle[row][col] == '-':
				begin = row
				end = row
				while begin > 0 and puzzle[begin - 1][col] != '+':
					begin -= 1
				while end < maxrow - 1 and puzzle[end + 1][col] != '+':
					end += 1
				size = end - begin + 1
				for word in words:
					if len(word) == size:
						puzzle2 = [ro.copy() for ro in puzzle.copy()]
						for (ix, chr) in enumerate(word):
							chr2 = puzzle[begin + ix][col]
							if chr2 != '-' and chr2 != chr:
								break
							puzzle2[begin + ix][col] = chr
						else:
							words2 = words.copy()
							words2.remove(word)
							solved = solve(puzzle2, words2)
							if solved:
								return solved
				begin = col
				end = col
				while begin > 0 and puzzle[row][begin - 1] != '+':
					begin -= 1
				while end < maxcol - 1 and puzzle[row][end + 1] != '+':
					end += 1
				size = end - begin + 1
				for word in words:
					if len(word) == size:
						puzzle2 = [ro.copy() for ro in puzzle.copy()]
						for (ix, chr) in enumerate(word):
							chr2 = puzzle[row][begin + ix]
							if chr2 != '-' and chr2 != chr:
								break
							puzzle2[row][begin + ix] = chr
						else:
							words2 = words.copy()
							words2.remove(word)
							solved = solve(puzzle2, words2)
							if solved:
								return solved
	return None
puzzle = [list(input()) for ix in range(maxrow)]
words = set(input().split(sep=';'))
puzzle = solve(puzzle, words)
if puzzle is None:
	print('No solution found')
else:
	for row in puzzle:
		print(''.join(row))


solution = []
spaces = []
blanks = []

class Space:

	def __init__(self, start, length, vertical, taken):
		self.start = start
		self.length = length
		self.vertical = vertical
		self.taken = taken

def main():
	(solution, spaces) = readGrid()
	words = set(input().split(';'))
	findSol(solution, spaces, words)
	for row in solution:
		print(''.join(row))

def readGrid():
	rows = []
	for i in range(10):
		row = input()
		rows.append(row)
	row_spaces = countSpaces(rows)
	cols = []
	for x in range(10):
		col = ''
		for y in range(10):
			col += rows[y][x]
		cols.append(col)
	col_spaces = countSpaces(cols, vertical=True)
	return ([list(row) for row in rows], row_spaces + col_spaces)

def countSpaces(lines, vertical=False):
	spaces = []
	n = 0
	for line in lines:
		for j in whereAreSpaces(line):
			(index, length) = j
			if vertical == True:
				start = (index, n)
			else:
				start = (n, index)
			spaces.append(Space(start, length, vertical, False))
		n += 1
	return spaces

def whereAreSpaces(line):
	spaces = []
	for blanks in line.split('+'):
		length = len(blanks)
		if length > 1:
			index = 0
			while index < length:
				index = line.find(blanks, index)
				if line == -1:
					break
				spaces.append((index, length))
				index += length
	return spaces

def findSol(grid, spaces, words):
	if len(words) == 0:
		return True
	for word in words:
		for space in spaces:
			if canAddWord(grid, space, word):
				before = addWord(grid, space, word)
				space.taken = True
				new_words = set(words)
				new_words.remove(word)
				if findSol(grid, spaces, new_words):
					return True
				addWord(grid, space, before)
				space.taken = False
	return False

def canAddWord(grid, space, word):
	if space.taken or len(word) != space.length:
		return False
	(row, col) = space.start
	for i in word:
		if not (grid[row][col] == '-' or grid[row][col] == i):
			return False
		(row, col) = nextSpace(row, col, space.vertical)
	return True

def addWord(grid, space, word):
	new_grid = []
	(row, col) = space.start
	for char in word:
		new_grid.append(grid[row][col])
		grid[row][col] = char
		(row, col) = nextSpace(row, col, space.vertical)
	return new_grid

def nextSpace(row, col, vertical):
	if vertical is True:
		return (row + 1, col)
	else:
		return (row, col + 1)
main()


def setYword(cells, x, y, words, word):
	for i in range(len(word)):
		if y + i < 10:
			if cells[11 * x + y + i] == '-' or cells[11 * x + y + i] == word[i]:
				cells[11 * x + y + i] = word[i]
			else:
				return
		else:
			return
	words.remove(word)
	if len(words) == 0:
		return ''.join(cells)
	return decide(cells, words)

def setXword(cells, x, y, words, word):
	for i in range(len(word)):
		if x + i < 10:
			if cells[11 * (x + i) + y] == '-' or cells[11 * (x + i) + y] == word[i]:
				cells[11 * (x + i) + y] = word[i]
			else:
				return
		else:
			return
	words.remove(word)
	if len(words) == 0:
		return ''.join(cells)
	return decide(cells, words)

def decide(cells, words):
	startWord = 0
	for i in range(10):
		startWord = 0
		for j in range(10):
			if cells[11 * i + j] == '-' and startWord == 0:
				for w in words:
					r = setYword(list(cells), i, j, list(words), w)
					if r != None:
						return r
	for i in range(10):
		startWord = 0
		for j in range(10):
			if cells[11 * j + i] == '-' and startWord == 0:
				for w in words:
					r = setXword(list(cells), j, i, list(words), w)
					if r != None:
						return r
X = ''
for i in range(10):
	X += input() + '\n'
Y = input()
words = []
word = ''
for i in Y:
	if i == ';':
		words.append(word)
		word = ''
	else:
		word += i
words.append(word)
cells = X
print(decide(list(cells), words))


import itertools
A = [input() for i in range(10)]
(horizontal, vertical) = ([], [])
for lst in (horizontal, vertical):
	for row in range(10):
		for (c, g) in itertools.groupby(range(10), key=lambda x: A[row][x]):
			l = list(g)
			if c == '-' and len(l) > 1:
				lst.append([row, l[0], l[-1]])
	A = list(map(list, zip(*A)))
intersections = [(i, column[0] - row[1], j, row[0] - column[1]) for (i, row) in enumerate(horizontal) for (j, column) in enumerate(vertical) if row[1] <= column[0] <= row[2] and column[1] <= row[0] <= column[2]]
words = input().split(';')
result = None
for l in itertools.permutations(words, len(words)):
	if all((len(l[i]) == horizontal[i][2] - horizontal[i][1] + 1 for i in range(len(horizontal)))) and all((len(l[i + len(horizontal)]) == vertical[i][2] - vertical[i][1] + 1 for i in range(len(vertical)))) and all((l[i[0]][i[1]] == l[i[2] + len(horizontal)][i[3]] for i in intersections)):
		result = l
		break
for (i, x) in enumerate(horizontal):
	A[x[0]][x[1]:x[2] + 1] = result[i]
A = list(map(list, zip(*A)))
for (i, x) in enumerate(vertical):
	A[x[0]][x[1]:x[2] + 1] = result[i + len(horizontal)]
A = list(map(list, zip(*A)))
print(*(''.join(x) for x in A), sep='\n')


import itertools
A = [input() for i in range(10)]
(horizontal, vertical) = ([], [])
for lst in (horizontal, vertical):
	for row in range(10):
		for (c, g) in itertools.groupby(range(10), key=lambda x: A[row][x]):
			l = list(g)
			if c == '-' and len(l) > 1:
				lst.append([row, l[0], l[-1]])
	A = list(map(list, zip(*A)))
intersections = [(i, column[0] - row[1], j, row[0] - column[1]) for (i, row) in enumerate(horizontal) for (j, column) in enumerate(vertical) if row[1] <= column[0] <= row[2] and column[1] <= row[0] <= column[2]]
words = input().split(';')
result = None
for l in itertools.permutations(words, len(words)):
	if all((len(l[i]) == horizontal[i][2] - horizontal[i][1] + 1 for i in range(len(horizontal)))) and all((len(l[i + len(horizontal)]) == vertical[i][2] - vertical[i][1] + 1 for i in range(len(vertical)))) and all((l[i[0]][i[1]] == l[i[2] + len(horizontal)][i[3]] for i in intersections)):
		result = l
		break
for (i, x) in enumerate(horizontal):
	A[x[0]][x[1]:x[2] + 1] = result[i]
A = list(map(list, zip(*A)))
for (i, x) in enumerate(vertical):
	A[x[0]][x[1]:x[2] + 1] = result[i + len(horizontal)]
A = list(map(list, zip(*A)))
print(*(''.join(x) for x in A), sep='\n')


solution = []
spaces = []
blanks = []

class Space:

	def __init__(self, start, length, vertical, taken):
		self.start = start
		self.length = length
		self.vertical = vertical
		self.taken = taken

def main():
	(solution, spaces) = readGrid()
	words = set(input().split(';'))
	findSol(solution, spaces, words)
	for row in solution:
		print(''.join(row))

def readGrid():
	rows = []
	for i in range(10):
		row = input()
		rows.append(row)
	row_spaces = countSpaces(rows)
	cols = []
	for x in range(10):
		col = ''
		for y in range(10):
			col += rows[y][x]
		cols.append(col)
	col_spaces = countSpaces(cols, vertical=True)
	return ([list(row) for row in rows], row_spaces + col_spaces)

def countSpaces(lines, vertical=False):
	spaces = []
	n = 0
	for line in lines:
		for j in whereAreSpaces(line):
			(index, length) = j
			if vertical == True:
				start = (index, n)
			else:
				start = (n, index)
			spaces.append(Space(start, length, vertical, False))
		n += 1
	return spaces

def whereAreSpaces(line):
	spaces = []
	for blanks in line.split('+'):
		length = len(blanks)
		if length > 1:
			index = 0
			while index < length:
				index = line.find(blanks, index)
				if line == -1:
					break
				spaces.append((index, length))
				index += length
	return spaces

def findSol(grid, spaces, words):
	if len(words) == 0:
		return True
	for word in words:
		for space in spaces:
			if canAddWord(grid, space, word):
				before = addWord(grid, space, word)
				space.taken = True
				new_words = set(words)
				new_words.remove(word)
				if findSol(grid, spaces, new_words):
					return True
				addWord(grid, space, before)
				space.taken = False
	return False

def canAddWord(grid, space, word):
	if space.taken or len(word) != space.length:
		return False
	(row, col) = space.start
	for i in word:
		if not (grid[row][col] == '-' or grid[row][col] == i):
			return False
		(row, col) = nextSpace(row, col, space.vertical)
	return True

def addWord(grid, space, word):
	new_grid = []
	(row, col) = space.start
	for char in word:
		new_grid.append(grid[row][col])
		grid[row][col] = char
		(row, col) = nextSpace(row, col, space.vertical)
	return new_grid

def nextSpace(row, col, vertical):
	if vertical is True:
		return (row + 1, col)
	else:
		return (row, col + 1)
main()


import itertools
A = [input() for i in range(10)]
(horizontal, vertical) = ([], [])
for lst in (horizontal, vertical):
	for row in range(10):
		for (c, g) in itertools.groupby(range(10), key=lambda x: A[row][x]):
			l = list(g)
			if c == '-' and len(l) > 1:
				lst.append([row, l[0], l[-1]])
	A = list(map(list, zip(*A)))
words = input().split(';')
intersections = [(h_idx, v[0] - h[1], v_idx, h[0] - v[1]) for (h_idx, h) in enumerate(horizontal) for (v_idx, v) in enumerate(vertical) if v[1] <= h[0] <= v[2] and h[1] <= v[0] <= h[2]]
for l in itertools.permutations(words, len(words)):
	if all((len(l[i]) == horizontal[i][2] - horizontal[i][1] + 1 for i in range(len(horizontal)))) and all((len(l[i + len(horizontal)]) == vertical[i][2] - vertical[i][1] + 1 for i in range(len(vertical)))) and all((l[i[0]][i[1]] == l[i[2] + len(horizontal)][i[3]] for i in intersections)):
		result = l
		break
for (i, x) in enumerate(horizontal):
	A[x[0]][x[1]:x[2] + 1] = result[i]
A = list(map(list, zip(*A)))
for (i, x) in enumerate(vertical):
	A[x[0]][x[1]:x[2] + 1] = result[i + len(horizontal)]
A = list(map(list, zip(*A)))
print(*(''.join(x) for x in A), sep='\n')


import sys
N = 10
cw = [list(input()) for l in range(N)]
w = input().split(';')

def valid(i, j):
	if i < 0 or i >= N or j < 0 or (j >= N):
		return False
	if cw[i][j] != '-':
		return False
	return True

def try_words(i, j, di, dj, excl):
	if valid(i, j - 1):
		while j >= 0 and cw[i][j] != '+':
			j -= 1
		j += 1
		dj = 1
	if valid(i - 1, j):
		while i >= 0 and cw[i][j] != '+':
			i -= 1
		i += 1
		di = 1
	s_i = i
	s_j = j
	for w_i in w:
		if w_i in excl:
			continue
		f = True
		nexts = []
		trace = []
		idx = 0
		i = s_i
		j = s_j
		while i >= 0 and i < N and (j >= 0) and (j < N):
			if cw[i][j] == '+' and idx == len(w_i):
				break
			elif idx < len(w_i) and (cw[i][j] == '-' or cw[i][j] == w_i[idx]):
				trace.append((i, j))
				cw[i][j] = w_i[idx]
			else:
				f = False
				break
			if di == 0:
				if valid(i - 1, j):
					nexts.append((i, j, -1, 0))
				elif valid(i + 1, j):
					nexts.append((i, j, 1, 0))
			if dj == 0:
				if valid(i, j - 1):
					nexts.append((i, j, 0, -1))
				elif valid(i, j + 1):
					nexts.append((i, j, 0, 1))
			i += di
			j += dj
			idx += 1
		if not f:
			for (i, j) in trace:
				cw[i][j] = '-'
			continue
		for (_i, _j, _di, _dj) in nexts:
			f = f and try_words(_i, _j, _di, _dj, excl + [w_i])
		if not f:
			for (i, j) in trace:
				cw[i][j] = '-'
			continue
		if f:
			return True
	return False

def solve(i, j):
	if valid(i + 1, j):
		return try_words(i, j, 1, 0, [])
	else:
		return try_words(i, j, 0, 1, [])
i = 0
while i < N:
	j = 0
	while j < N:
		if cw[i][j] == '-':
			solve(i, j)
		j += 1
	i += 1
for q in cw:
	print(''.join(q))


import itertools as it

class Extent:

	def __init__(self, r0, c0, r1, c1):
		self.r0 = r0
		self.c0 = c0
		self.r1 = r1
		self.c1 = c1
		self.word = None

	def __len__(self):
		return self.r1 - self.r0 + 1 if self.c0 == self.c1 else self.c1 - self.c0 + 1

	def __str__(self):
		return '[{}]'.format(', '.join(map(str, [self.r0, self.c0, self.r1, self.c1])))

	def fill(self, grid):
		if self.r0 == self.r1:
			row = grid[self.r0]
			for i in range(self.c1 - self.c0 + 1):
				if row[i + self.c0] not in ['-', self.word[i]]:
					return False
				row[i + self.c0] = self.word[i]
		else:
			for i in range(self.r1 - self.r0 + 1):
				if grid[i + self.r0][self.c0] not in ['-', self.word[i]]:
					return False
				grid[i + self.r0][self.c0] = self.word[i]
		return True

	def set(self, word):
		if self.word is None:
			if len(word) == len(self):
				self.word = word
				return True

	def reset(self):
		self.word = None
grid = [list(input().rstrip()) for _ in range(10)]
words = input().rstrip().split(';')
extents = []

def get_spaces(row):
	g = enumerate(row)
	g = it.groupby(g, lambda p: p[1])
	g = ([i for (i, _) in p] for (k, p) in g if k == '-')
	g = (l for l in g if len(l) >= 2)
	return g
for (r, row) in enumerate(grid):
	for l in get_spaces(row):
		extents.append(Extent(r, l[0], r, l[-1]))
for (c, column) in enumerate(zip(*grid)):
	for l in get_spaces(column):
		extents.append(Extent(l[0], c, l[-1], c))

def print_grid():
	filled_grid = [row[:] for row in grid]
	if all((extent.fill(filled_grid) for extent in extents)):
		g = (''.join(row) for row in filled_grid)
		print(*g, sep='\n')
		return True

def doit(n):
	if n == 0:
		return print_grid()
	else:
		for word in words:
			for extent in extents:
				if extent.set(word):
					if doit(n - 1):
						return True
					else:
						extent.reset()
doit(len(words))


from typing import List
import copy

class Pos:
	x = 0
	y = 0

	def __init__(self, x: int, y: int):
		self.x = x
		self.y = y

class Start:
	position = Pos(0, 0)
	direction = ''
	length = 0

	def __init__(self, position: Pos, direction: str, length: int):
		self.position = position
		self.direction = direction
		self.length = length

def x_start(p: Pos, puzzle: list):
	if puzzle[p.x][p.y] == '+':
		return None
	if p.x == 0 or puzzle[p.x - 1][p.y] == '+':
		count = 1
		x = p.x + 1
		l = len(puzzle)
		while x < l:
			if puzzle[x][p.y] == '-':
				count += 1
				x += 1
			else:
				break
		if count > 1:
			return Start(p, 'x', count)
		else:
			return None
	else:
		return None

def y_start(p: Pos, puzzle: list):
	if puzzle[p.x][p.y] == '+':
		return None
	if p.y == 0 or puzzle[p.x][p.y - 1] == '+':
		count = 1
		y = p.y + 1
		l = len(puzzle[p.x])
		while y < l:
			if puzzle[p.x][y] == '-':
				count += 1
				y += 1
			else:
				break
		if count > 1:
			return Start(p, 'y', count)
		else:
			return None
	else:
		return None

def find_starts(puzzle) -> list:
	starts = []
	c = len(puzzle)
	for x in range(c):
		for y in range(c):
			p = Pos(x, y)
			xs = x_start(p, puzzle)
			if xs is not None:
				starts.append(xs)
			ys = y_start(p, puzzle)
			if ys is not None:
				starts.append(ys)
	return starts

def word_fit_puzzle(word: str, puzzle: list, start: Start) -> bool:
	if not len(word) == start.length:
		return False
	d = start.direction
	x = start.position.x
	y = start.position.y
	for char in word:
		if puzzle[x][y] == '-' or puzzle[x][y] == char:
			if d == 'x':
				x += 1
			else:
				y += 1
		else:
			return False
	return True

def fill_puzzle(word: str, puzzle: list, start: Start):
	d = start.direction
	x = start.position.x
	y = start.position.y
	for char in word:
		puzzle[x][y] = char
		if d == 'x':
			x += 1
		else:
			y += 1

def solve_puzzle(puzzle: list, words: List[str], starts: List[Start]):
	if len(starts) == 0:
		return puzzle
	for start in starts:
		for word in words:
			if word_fit_puzzle(word, puzzle, start):
				new_puzzle = copy.deepcopy(puzzle)
				fill_puzzle(word, new_puzzle, start)
				new_words = list(words)
				new_words.remove(word)
				new_starts = list(starts)
				new_starts.remove(start)
				solved = solve_puzzle(new_puzzle, new_words, new_starts)
				if solved is not None:
					return solved
	return None
cw = []
for i in range(0, 10):
	cw.append(list(input().strip()))
cw_words = input().strip().split(';')
cw_starts = find_starts(cw)
cw_solved = solve_puzzle(cw, cw_words, cw_starts)
print('\n'.join(map(''.join, cw_solved)))


def fillrow(row, flags, s):
	if row == len(rows):
		fillcol(0, flags, s)
	else:
		lenWord = rows[row][2] - rows[row][1] + 1
		for i in range(len(words)):
			if not flags[i]:
				continue
			if len(words[i]) != lenWord:
				continue
			else:
				l = rows[row][0]
				start = rows[row][1]
				end = rows[row][2]
				if end != 9:
					s[l] = s[l][:start] + words[i] + s[l][end + 1:]
				else:
					s[l] = s[l][:start] + words[i]
				flags[i] = False
				fillrow(row + 1, flags, s)
				flags[i] = True

def fillcol(col, flags, s):
	if col == len(cols):
		out()
	else:
		lenWord = cols[col][2] - cols[col][1] + 1
		for i in range(len(words)):
			if not flags[i]:
				continue
			if len(words[i]) != lenWord:
				continue
			else:
				c = cols[col][0]
				start = cols[col][1]
				end = cols[col][2]
				for j in range(start, end + 1):
					if s[j][c] != '-' and s[j][c] != words[i][j - start]:
						break
				if j == end and (s[j][c] == '-' or s[j][c] == words[i][end - start]):
					flags[i] = False
					cols2.append(i)
					fillcol(col + 1, flags, s)
					cols2.remove(i)
					flags[i] = True

def out():
	for i in range(len(cols)):
		c = cols[i][0]
		start = cols[i][1]
		end = cols[i][2]
		for j in range(start, end + 1):
			if c == 0:
				s[j] = words[cols2[i]][j - start] + s[j][1:]
			elif c == 9:
				s[j] = s[j][:c] + words[cols2[i]][j - start]
			else:
				s[j] = s[j][:c] + words[cols2[i]][j - start] + s[j][c + 1:]
	for i in range(10):
		print(s[i])
s = []
for i in range(10):
	s.append(input())
rows = []
cols = []
cols2 = []
for i in range(10):
	j = 0
	while j < 9:
		if s[i][j] == '-' and s[i][j + 1] == '-':
			start = j
			j += 1
			while j < 9 and s[i][j + 1] != '+':
				j += 1
			end = j
			rows.append((i, start, end))
		j += 1
for i in range(10):
	j = 0
	while j < 9:
		if s[j][i] == '-' and s[j + 1][i] == '-':
			start = j
			j += 1
			while j < 9 and s[j + 1][i] != '+':
				j += 1
			cols.append((i, start, j))
		j += 1
words = str.split(input(), ';')
flags = []
for i in range(len(words)):
	flags.append(True)
fillrow(0, flags, s)


import itertools
A = [input() for i in range(10)]
(horizontal, vertical) = ([], [])
for lst in (horizontal, vertical):
	for row in range(10):
		for (c, g) in itertools.groupby(range(10), key=lambda x: A[row][x]):
			l = list(g)
			if c == '-' and len(l) > 1:
				lst.append([row, l[0], l[-1]])
	A = list(map(list, zip(*A)))
intersections = [(i, column[0] - row[1], j, row[0] - column[1]) for (i, row) in enumerate(horizontal) for (j, column) in enumerate(vertical) if row[1] <= column[0] <= row[2] and column[1] <= row[0] <= column[2]]
words = input().split(';')
result = None
for l in itertools.permutations(words, len(words)):
	if all((len(l[i]) == horizontal[i][2] - horizontal[i][1] + 1 for i in range(len(horizontal)))) and all((len(l[i + len(horizontal)]) == vertical[i][2] - vertical[i][1] + 1 for i in range(len(vertical)))) and all((l[i[0]][i[1]] == l[i[2] + len(horizontal)][i[3]] for i in intersections)):
		result = l
		break
for (i, x) in enumerate(horizontal):
	A[x[0]][x[1]:x[2] + 1] = result[i]
A = list(map(list, zip(*A)))
for (i, x) in enumerate(vertical):
	A[x[0]][x[1]:x[2] + 1] = result[i + len(horizontal)]
A = list(map(list, zip(*A)))
print(*(''.join(x) for x in A), sep='\n')


import copy
board = []
for i in range(10):
	board.append(list(input()))
size = len(board)
words = input().split(';')
used = []
horiz = []
vert = []
for row in range(size):
	for col in range(size):
		if board[row][col] == '-':
			if col == 0 or board[row][col - 1] == '+':
				horiz.append([row, col, 1, 0])
			else:
				horiz[-1][-2] += 1
spaces = [x for x in horiz if x[-2] != 1]
for col in range(size):
	for row in range(size):
		if board[row][col] == '-':
			if row == 0 or board[row - 1][col] == '+':
				vert.append([row, col, 1, 1])
			else:
				vert[-1][-2] += 1
spaces += [x for x in vert if x[-2] != 1]

def fill(idx, in_spaces, in_board):
	if in_spaces == []:
		for n in in_board:
			print(''.join(n))
		return 1
	for spot in in_spaces:
		if idx < len(words) and len(words[idx]) == spot[2]:
			h1 = spot[0]
			v1 = spot[1]
			nboard = copy.deepcopy(in_board)
			for letr in words[idx]:
				if in_board[h1][v1] == '-' or in_board[h1][v1] == letr:
					nboard[h1][v1] = letr
					if spot[-1] == 0:
						v1 += 1
					else:
						h1 += 1
				else:
					return 0
			nspaces = copy.deepcopy(in_spaces)
			nspaces.remove(spot)
			nidx = idx + 1
			if fill(nidx, nspaces, nboard) != 0:
				return 1
	return 0
fill(0, spaces, board)


import sys
import itertools
import string
lines = []
for line in sys.stdin.readlines():
	lines.append(line.strip())
puzzle = lines[:10]
words = lines[10].split(';')
slots = set()
for (row_idx, row) in enumerate(puzzle):
	start = -1
	end = -1
	for i in range(len(row)):
		if start == -1 and row[i] == '-':
			start = i
		if start != -1:
			if row[i] == '+':
				end = i - 1
			elif i == len(row) - 1:
				end = i
		if start != -1 and end != -1 and (start != end):
			slots.add(('r', row_idx, start, end))
			start = -1
			end = -1
		if start == end:
			start = -1
			end = -1
for col_idx in range(len(puzzle[0])):
	col = []
	for row in puzzle:
		col.append(row[col_idx])
	start = -1
	end = -1
	for i in range(len(col)):
		if start == -1 and col[i] == '-':
			start = i
		if start != -1:
			if col[i] == '+':
				end = i - 1
			elif i == len(col) - 1:
				end = i
		if start != -1 and end != -1 and (start != end):
			slots.add(('c', col_idx, start, end))
			start = -1
			end = -1
		if start == end:
			start = -1
			end = -1
assert len(words) == len(slots)

def intersect(slotA, slotB):
	return slotA[1] >= slotB[2] and slotA[1] <= slotB[3] and (slotB[1] >= slotA[2]) and (slotB[1] <= slotA[3])

def check(words_in_slots):
	for (word, slot) in words_in_slots:
		for (wordx, slotx) in words_in_slots:
			if word != wordx and slot[0] != slotx[0] and intersect(slot, slotx):
				if slot[0] == 'r':
					row_idx = slot[1] - slotx[2]
					row_word = word
					col_idx = slotx[1] - slot[2]
					col_word = wordx
				else:
					row_idx = slotx[1] - slot[2]
					row_word = wordx
					col_idx = slot[1] - slotx[2]
					col_word = word
				if row_word[col_idx] != col_word[row_idx]:
					return False
	return True
puzzle_copy = [list(row) for row in puzzle]
for perm in itertools.permutations(words, len(words)):
	words_in_slots = []
	slots_remaining = set(slots)
	for (idx, word) in enumerate(perm):
		fit = False
		fitted_slot = None
		for slot in slots_remaining:
			slot_len = slot[3] - slot[2] + 1
			if len(word) == slot_len:
				words_in_slots.append((word, slot))
				fitted_slot = slot
				fit = True
				break
		if fit == True:
			slots_remaining.remove(fitted_slot)
	if len(slots_remaining) != 0:
		continue
	elif check(words_in_slots):
		for (word, slot) in words_in_slots:
			slot_start = slot[2]
			if slot[0] == 'r':
				slot_row = slot[1]
				for (idx, c) in enumerate(word):
					puzzle_copy[slot_row][slot_start + idx] = c
			else:
				slot_col = slot[1]
				c_idx = 0
				for row_idx in range(slot[2], slot[3] + 1):
					puzzle_copy[row_idx][slot_col] = word[c_idx]
					c_idx += 1
		for row in puzzle_copy:
			print(''.join(map(str, row)))
		break


def copy(mat):
	return [[elem for elem in row] for row in mat]

def output(grid):
	for row in grid:
		print(*row, sep='')

def solve(grid, words):
	if words:
		word = words.pop()
		for x in range(len(grid)):
			row = grid[x]
			j = 0
			for i in range(len(row)):
				if row[i] == '+':
					if j != len(word):
						j = 0
					else:
						break
				elif row[i] == '-' or row[i] == word[j]:
					if j == 0:
						begin = i
					j += 1
				else:
					j = 0
			if j == len(word):
				new_grid = copy(grid)
				new_grid[x][begin:begin + j] = word
				sol = solve(new_grid, words[:])
				if sol:
					return sol
		for x in range(len(grid[0])):
			row = [line[x] for line in grid]
			j = 0
			for i in range(len(row)):
				if row[i] == '+':
					if j != len(word):
						j = 0
					else:
						break
				elif row[i] == '-' or row[i] == word[j]:
					if j == 0:
						begin = i
					j += 1
				else:
					j = 0
			if j == len(word):
				new_grid = copy(grid)
				for (i, ch) in enumerate(word):
					new_grid[begin + i][x] = ch
				sol = solve(new_grid, words[:])
				if sol:
					return sol
		return None
	return grid
grid = [[ch for ch in input()] for i in range(10)]
words = input().split(';')
output(solve(grid, words))


import copy

def print_grid(grid):
	for line in grid:
		for c in line:
			print(c, end='')
		print()
	print()

def try_direction(grid, i, j, word, direction):
	size = 0
	if i - direction[0] >= 0 and i - direction[0] < len(grid) and (j - direction[1] >= 0) and (j - direction[1] < len(grid)) and (grid[i - direction[0]][j - direction[1]] == '-'):
		return False
	while i >= 0 and i < len(grid) and (j >= 0) and (j < len(grid)) and (grid[i][j] == '-' or (size < len(word) and word[size] == grid[i][j])):
		size += 1
		i += direction[0]
		j += direction[1]
	return size == len(word)

def write_word(grid, word, i, j, dir):
	for c in word:
		grid[i][j] = c
		if dir == 'up':
			i -= 1
		elif dir == 'down':
			i += 1
		elif dir == 'left':
			j -= 1
		else:
			j += 1

def erase_word(grid, word, i, j, dir):
	for c in word:
		grid[i][j] = '-'
		if dir == 'up':
			i -= 1
		elif dir == 'down':
			i += 1
		elif dir == 'left':
			j -= 1
		else:
			j += 1

def try_place_word(grid, words, index, solutions):
	if index >= len(words):
		solutions.append(grid)
		return
	word = words[index]
	new_grid = copy.deepcopy(grid)
	for i in range(len(new_grid)):
		for j in range(len(new_grid)):
			if new_grid[i][j] != '+':
				if try_direction(new_grid, i, j, word, (-1, 0)):
					write_word(new_grid, word, i, j, 'up')
					try_place_word(new_grid, words, index + 1, solutions)
					if len(solutions) == 0:
						erase_word(new_grid, word, i, j, 'up')
				elif try_direction(new_grid, i, j, word, (1, 0)):
					write_word(new_grid, word, i, j, 'down')
					try_place_word(new_grid, words, index + 1, solutions)
					if len(solutions) == 0:
						erase_word(new_grid, word, i, j, 'down')
				elif try_direction(new_grid, i, j, word, (0, -1)):
					write_word(new_grid, word, i, j, 'left')
					try_place_word(new_grid, words, index + 1, solutions)
					if len(solutions) == 0:
						erase_word(new_grid, word, i, j, 'left')
				elif try_direction(new_grid, i, j, word, (0, 1)):
					write_word(new_grid, word, i, j, 'right')
					try_place_word(new_grid, words, index + 1, solutions)
					if len(solutions) == 0:
						erase_word(new_grid, word, i, j, 'right')
grid = []
solutions = []
for _ in range(10):
	grid.append(list(input()))
words = input().split(';')
try_place_word(grid, words, 0, solutions)
for solution in solutions:
	print_grid(solution)


import pprint
pp = pprint.PrettyPrinter(indent=4)

def create_pos(grid):
	pos = []
	for col in range(10):
		word_slot = []
		for row in range(10):
			if grid[row][col] == '-':
				word_slot.append((col, row))
			else:
				if len(word_slot) > 1:
					pos.append(word_slot)
				word_slot = []
		if len(word_slot) > 1:
			pos.append(word_slot)
	for row in range(10):
		word_slot = []
		for col in range(10):
			if grid[row][col] == '-':
				word_slot.append((col, row))
			else:
				if len(word_slot) > 1:
					pos.append(word_slot)
				word_slot = []
		if len(word_slot) > 1:
			pos.append(word_slot)
	return pos

def get_word_fits(coord, words):
	word_fits = []
	for word in words:
		match = True
		if len(word) != len(coord):
			match = False
		else:
			for (i, lett) in enumerate(list(coord)):
				if isinstance(lett, str) and lett != word[i]:
					match = False
		if match:
			word_fits.append(word)
	return word_fits

def solve(words, pos, vals):
	if len(pos) == 0:
		return vals
	pos_copy = list(pos)
	coord = [vals[x] if x in vals else x for x in pos_copy.pop()]
	for word in get_word_fits(coord, words):
		tmp_vals = dict(vals)
		for (i, coord_val) in enumerate(coord):
			if isinstance(coord_val, tuple):
				tmp_vals[coord_val] = word[i]
		word_copy = list(words)
		word_copy.remove(word)
		if len(word_copy) == 0:
			return tmp_vals
		ret_vals = solve(word_copy, pos_copy, tmp_vals)
		if ret_vals:
			return ret_vals
	return {}
grid = [list(input()) for _ in range(10)]
word_list = input().split(';')
positions = create_pos(grid)
vals = solve(word_list, positions, {})
for row in range(10):
	full_row = ''
	for col in range(10):
		if (col, row) in vals:
			full_row += vals[col, row]
		else:
			full_row += '+'
	print(full_row)


import itertools
A = [input() for i in range(10)]
(horizontal, vertical) = ([], [])
for lst in (horizontal, vertical):
	for row in range(10):
		for (c, g) in itertools.groupby(range(10), key=lambda x: A[row][x]):
			l = list(g)
			if c == '-' and len(l) > 1:
				lst.append([row, l[0], l[-1]])
	A = list(map(list, zip(*A)))
intersections = [(i, column[0] - row[1], j, row[0] - column[1]) for (i, row) in enumerate(horizontal) for (j, column) in enumerate(vertical) if row[1] <= column[0] <= row[2] and column[1] <= row[0] <= column[2]]
words = input().split(';')
result = None
for l in itertools.permutations(words, len(words)):
	if all((len(l[i]) == horizontal[i][2] - horizontal[i][1] + 1 for i in range(len(horizontal)))) and all((len(l[i + len(horizontal)]) == vertical[i][2] - vertical[i][1] + 1 for i in range(len(vertical)))) and all((l[i[0]][i[1]] == l[i[2] + len(horizontal)][i[3]] for i in intersections)):
		result = l
		break
for (i, x) in enumerate(horizontal):
	A[x[0]][x[1]:x[2] + 1] = result[i]
A = list(map(list, zip(*A)))
for (i, x) in enumerate(vertical):
	A[x[0]][x[1]:x[2] + 1] = result[i + len(horizontal)]
A = list(map(list, zip(*A)))
print(*(''.join(x) for x in A), sep='\n')


GRID = [input().strip() for _ in range(10)]
WORDS = input().strip().split(';')

def getSlots(grid):

	def scan(g, s):
		for i in range(10):
			c = 0
			for segment in g[i].split('+'):
				segLength = len(segment)
				if segLength >= 2:
					s.append((i, c, c + segLength - 1))
					c += segLength
				else:
					c += segLength + 1
	horizontalSlots = []
	verticalSlots = []
	scan(grid, horizontalSlots)
	transposedGrid = [''.join([grid[i][j] for i in range(10)]) for j in range(10)]
	scan(transposedGrid, verticalSlots)
	return (horizontalSlots, verticalSlots)

def getIntersections(horizontalSlots, verticalSlots):
	intersections = []
	for (hi, hs) in enumerate(horizontalSlots):
		for (vi, vs) in enumerate(verticalSlots):
			if (hs[0] <= vs[2] and hs[0] >= vs[1]) and (vs[0] <= hs[2] and vs[0] >= hs[1]):
				intersections.append((hi, vs[0] - hs[1], vi, hs[0] - vs[1]))
	return intersections

def findAnswer(hLengths, vLengths, intersections, hWords, vWords, remWords):
	if len(hWords) < len(hLengths):
		for (i, w) in enumerate(remWords):
			if len(w) == hLengths[len(hWords)]:
				ret = findAnswer(hLengths, vLengths, intersections, hWords + [w], vWords, remWords[:i] + remWords[i + 1:])
				if ret:
					return ret
	elif len(vWords) < len(vLengths):
		for (i, w) in enumerate(remWords):
			if len(w) == vLengths[len(vWords)]:
				ret = findAnswer(hLengths, vLengths, intersections, hWords, vWords + [w], remWords[:i] + remWords[i + 1:])
				if ret:
					return ret
	else:
		for inter in intersections:
			if hWords[inter[0]][inter[1]] != vWords[inter[2]][inter[3]]:
				return
		return (hWords, vWords)

def getLengths(slots):
	return [s[2] - s[1] + 1 for s in slots]
(horizontalSlots, verticalSlots) = getSlots(GRID)
intersections = getIntersections(horizontalSlots, verticalSlots)
(hWords, vWords) = findAnswer(getLengths(horizontalSlots), getLengths(verticalSlots), intersections, [], [], WORDS)
explodedGRID = [[c for c in line] for line in GRID]
for (hi, w) in enumerate(hWords):
	for (i, c) in enumerate(w):
		explodedGRID[horizontalSlots[hi][0]][horizontalSlots[hi][1] + i] = c
for (vi, w) in enumerate(vWords):
	for (i, c) in enumerate(w):
		explodedGRID[verticalSlots[vi][1] + i][verticalSlots[vi][0]] = c
for line in explodedGRID:
	print(''.join(line))


grid = []
for i in range(10):
	grid.append(list(input().strip()))
words = input().strip().split(';')
num = len(words)
pos = []
for i in range(10):
	for j in range(10):
		if grid[i][j] != '-':
			continue
		if i == 0 or grid[i - 1][j] != '-':
			k = i + 1
			while k < 10 and grid[k][j] == '-':
				k += 1
			if k > i + 1:
				pos.append(('v', i, j, k - i))
		if j == 0 or grid[i][j - 1] != '-':
			k = j + 1
			while k < 10 and grid[i][k] == '-':
				k += 1
			if k > j + 1:
				pos.append(('h', i, j, k - j))
save = [['-'] * len(w) for w in words]
place = [0] * num
n = 0
while n < num:
	if place[n] < num:
		w = words[n]
		s = save[n]
		(d, i, j, k) = pos[place[n]]
		good = False
		if k == len(w):
			if d == 'h':
				for p in range(k):
					g = grid[i][j + p]
					if g != '-' and g != w[p]:
						break
					s[p] = g
				else:
					good = True
					for p in range(k):
						grid[i][j + p] = w[p]
			else:
				for p in range(k):
					g = grid[i + p][j]
					if g != '-' and g != w[p]:
						break
					s[p] = g
				else:
					good = True
					for p in range(k):
						grid[i + p][j] = w[p]
		if good:
			n += 1
		else:
			place[n] += 1
	else:
		place[n] = 0
		n -= 1
		s = save[n]
		(d, i, j, k) = pos[place[n]]
		if d == 'h':
			for p in range(k):
				grid[i][j + p] = s[p]
		else:
			for p in range(k):
				grid[i + p][j] = s[p]
		place[n] += 1
for row in grid:
	print(''.join(row))


import itertools
A = [input() for i in range(10)]
(horizontal, vertical) = ([], [])
for lst in (horizontal, vertical):
	for row in range(10):
		for (c, g) in itertools.groupby(range(10), key=lambda x: A[row][x]):
			l = list(g)
			if c == '-' and len(l) > 1:
				lst.append([row, l[0], l[-1]])
	A = list(map(list, zip(*A)))
intersections = [(i, column[0] - row[1], j, row[0] - column[1]) for (i, row) in enumerate(horizontal) for (j, column) in enumerate(vertical) if row[1] <= column[0] <= row[2] and column[1] <= row[0] <= column[2]]
words = input().split(';')
result = None
for l in itertools.permutations(words, len(words)):
	if all((len(l[i]) == horizontal[i][2] - horizontal[i][1] + 1 for i in range(len(horizontal)))) and all((len(l[i + len(horizontal)]) == vertical[i][2] - vertical[i][1] + 1 for i in range(len(vertical)))) and all((l[i[0]][i[1]] == l[i[2] + len(horizontal)][i[3]] for i in intersections)):
		result = l
		break
for (i, x) in enumerate(horizontal):
	A[x[0]][x[1]:x[2] + 1] = result[i]
A = list(map(list, zip(*A)))
for (i, x) in enumerate(vertical):
	A[x[0]][x[1]:x[2] + 1] = result[i + len(horizontal)]
A = list(map(list, zip(*A)))
print(*(''.join(x) for x in A), sep='\n')


import re
board = [input().strip() for i in range(10)]
words = input().strip().split(';')
across = [(i, x.span(0)) for (i, row) in enumerate(board) for x in re.finditer('\\-{2,}', row)]
down = [(i, x.span(0)) for (i, row) in enumerate(zip(*board)) for x in re.finditer('\\-{2,}', ''.join(row))]

def try_fill(board, across, word):
	row = ''.join(board[across[0]])
	existing = row[across[1][0]:across[1][1]]
	if len(word) == len(existing) and all((c == '-' or c == word[i] for (i, c) in enumerate(existing))):
		return board[:across[0]] + [row[:across[1][0]] + word + row[across[1][1]:]] + board[across[0] + 1:]

def solve(board, across, down, words):
	if not across and (not down):
		return board
	for (i, word) in enumerate(words):
		solution = None
		if across:
			filled = try_fill(board, across[-1], word)
			if filled:
				solution = solve(filled, across[:-1], down, words[:i] + words[i + 1:])
		elif down:
			filled = try_fill(list(zip(*board)), down[-1], word)
			if filled:
				solution = solve(list(zip(*filled)), across, down[:-1], words[:i] + words[i + 1:])
		if solution:
			return solution
[print(''.join(row)) for row in solve(board, across, down, words)]


import copy
matrix_ori = [input() for _ in range(10)]
words = input().split(';')
matrix = [[char for char in string] for string in matrix_ori]
global output
output = None

def replace(matrix, word, loc, pos='h'):
	(r, c) = loc
	mat = copy.deepcopy(matrix)
	if pos == 'h':
		if c != 0 and mat[r][c - 1] == '-':
			return None
		elif c + len(word) > len(mat[0]):
			return None
		elif c + len(word) < len(mat[0]) and mat[r][c + len(word)] == '-':
			return None
		else:
			for i in range(len(word)):
				if mat[r][c + i] == '+':
					return None
				elif mat[r][c + i] != '-' and mat[r][c + i] != word[i]:
					return None
				else:
					mat[r][c + i] = word[i]
	elif pos == 'v':
		if r != 0 and mat[r - 1][c] == '-':
			return None
		elif r + len(word) > len(mat):
			return None
		elif r + len(word) < len(mat) and mat[r + len(word)][c] == '-':
			return None
		else:
			for i in range(len(word)):
				if mat[r + i][c] == '+':
					return None
				elif mat[r + i][c] != '-' and mat[r + i][c] != word[i]:
					return None
				else:
					mat[r + i][c] = word[i]
	return mat

def check(matrix):
	for i in range(len(matrix)):
		for j in range(len(matrix[0])):
			if matrix[i][j] == '-':
				return False
	return True

def fineprint(matrix):
	for row in matrix:
		print(''.join(row))

def edit(matrix, words):
	global output
	if check(matrix):
		output = matrix
	if output is None:
		mat = copy.deepcopy(matrix)
		for r in range(len(mat)):
			for c in range(len(mat[0])):
				if matrix[r][c] == '-':
					for pos in ('h', 'v'):
						for word in words:
							temp = replace(matrix, word, (r, c), pos)
							if temp != None:
								tempwords = copy.deepcopy(words)
								tempwords.remove(word)
								edit(temp, tempwords)
edit(matrix, words)
fineprint(output)


import itertools
A = [input() for i in range(10)]
(horizontal, vertical) = ([], [])
for lst in (horizontal, vertical):
	for row in range(10):
		for (c, g) in itertools.groupby(range(10), key=lambda x: A[row][x]):
			l = list(g)
			if c == '-' and len(l) > 1:
				lst.append([row, l[0], l[-1]])
	A = list(map(list, zip(*A)))
intersections = [(i, column[0] - row[1], j, row[0] - column[1]) for (i, row) in enumerate(horizontal) for (j, column) in enumerate(vertical) if row[1] <= column[0] <= row[2] and column[1] <= row[0] <= column[2]]
words = input().split(';')
result = None
for l in itertools.permutations(words, len(words)):
	if all((len(l[i]) == horizontal[i][2] - horizontal[i][1] + 1 for i in range(len(horizontal)))) and all((len(l[i + len(horizontal)]) == vertical[i][2] - vertical[i][1] + 1 for i in range(len(vertical)))) and all((l[i[0]][i[1]] == l[i[2] + len(horizontal)][i[3]] for i in intersections)):
		result = l
		break
for (i, x) in enumerate(horizontal):
	A[x[0]][x[1]:x[2] + 1] = result[i]
A = list(map(list, zip(*A)))
for (i, x) in enumerate(vertical):
	A[x[0]][x[1]:x[2] + 1] = result[i + len(horizontal)]
A = list(map(list, zip(*A)))
print(*(''.join(x) for x in A), sep='\n')


from copy import deepcopy

def print_grid(g):
	for i in range(N):
		print(''.join(g[i]))

def hfit(g_fitted, i0, j0, word):
	n = len(word)
	for k in range(n):
		i = i0 + k
		char = word[k]
		if i >= N or (g_fitted[i][j0] != '-' and g_fitted[i][j0] != char):
			return (False, g_fitted)
	for k in range(n):
		i = i0 + k
		char = word[k]
		g_fitted[i][j0] = char
	return (True, g_fitted)

def vfit(g_fitted, i0, j0, word):
	n = len(word)
	for k in range(n):
		j = j0 + k
		char = word[k]
		if j >= N or (g_fitted[i0][j] != '-' and g_fitted[i0][j] != char):
			return (False, g_fitted)
	for k in range(n):
		j = j0 + k
		char = word[k]
		g_fitted[i0][j] = char
	return (True, g_fitted)

def solve(g, words):
	hkey = ','.join([','.join([g[i][j] for j in range(N)]) for i in range(N)])
	if hkey in mem:
		return mem[hkey]
	if len(words) == 0 and '-' not in g:
		mem[hkey] = (True, g)
		return (True, g)
	for word in words:
		remaining_words = deepcopy(words)
		remaining_words.remove(word)
		for i in range(N):
			for j in range(N):
				g_fitted = deepcopy(g)
				(flag, g_fitted) = hfit(g_fitted, i, j, word)
				if flag:
					(flag, g_fitted) = solve(g_fitted, remaining_words)
					if flag:
						mem[hkey] = (flag, g_fitted)
						return (flag, g_fitted)
				g_fitted = deepcopy(g)
				(flag, g_fitted) = vfit(g_fitted, i, j, word)
				if flag:
					(flag, g_fitted) = solve(g_fitted, remaining_words)
					if flag:
						mem[hkey] = (flag, g_fitted)
						return (flag, g_fitted)
	mem[hkey] = (False, g)
	return (False, g)
N = 10
g = []
for _ in range(N):
	g.append(list(input()))
words = input().split(';')
mem = {}
(flag, g_fitted) = solve(g, words)
if flag:
	print_grid(g_fitted)
else:
	print('Something must have gone WRONG!')


import itertools
A = [input() for i in range(10)]
(horizontal, vertical) = ([], [])
for lst in (horizontal, vertical):
	for row in range(10):
		for (c, g) in itertools.groupby(range(10), key=lambda x: A[row][x]):
			l = list(g)
			if c == '-' and len(l) > 1:
				lst.append([row, l[0], l[-1]])
	A = list(map(list, zip(*A)))
intersections = [(i, column[0] - row[1], j, row[0] - column[1]) for (i, row) in enumerate(horizontal) for (j, column) in enumerate(vertical) if row[1] <= column[0] <= row[2] and column[1] <= row[0] <= column[2]]
words = input().split(';')
result = None
for l in itertools.permutations(words, len(words)):
	if all((len(l[i]) == horizontal[i][2] - horizontal[i][1] + 1 for i in range(len(horizontal)))) and all((len(l[i + len(horizontal)]) == vertical[i][2] - vertical[i][1] + 1 for i in range(len(vertical)))) and all((l[i[0]][i[1]] == l[i[2] + len(horizontal)][i[3]] for i in intersections)):
		result = l
		break
for (i, x) in enumerate(horizontal):
	A[x[0]][x[1]:x[2] + 1] = result[i]
A = list(map(list, zip(*A)))
for (i, x) in enumerate(vertical):
	A[x[0]][x[1]:x[2] + 1] = result[i + len(horizontal)]
A = list(map(list, zip(*A)))
print(*(''.join(x) for x in A), sep='\n')


import itertools
A = [input() for i in range(10)]
(horizontal, vertical) = ([], [])
for lst in (horizontal, vertical):
	for row in range(10):
		for (c, g) in itertools.groupby(range(10), key=lambda x: A[row][x]):
			l = list(g)
			if c == '-' and len(l) > 1:
				lst.append([row, l[0], l[-1]])
	A = list(map(list, zip(*A)))
intersections = [(i, column[0] - row[1], j, row[0] - column[1]) for (i, row) in enumerate(horizontal) for (j, column) in enumerate(vertical) if row[1] <= column[0] <= row[2] and column[1] <= row[0] <= column[2]]
words = input().split(';')
result = None
for l in itertools.permutations(words, len(words)):
	if all((len(l[i]) == horizontal[i][2] - horizontal[i][1] + 1 for i in range(len(horizontal)))) and all((len(l[i + len(horizontal)]) == vertical[i][2] - vertical[i][1] + 1 for i in range(len(vertical)))) and all((l[i[0]][i[1]] == l[i[2] + len(horizontal)][i[3]] for i in intersections)):
		result = l
		break
for (i, x) in enumerate(horizontal):
	A[x[0]][x[1]:x[2] + 1] = result[i]
A = list(map(list, zip(*A)))
for (i, x) in enumerate(vertical):
	A[x[0]][x[1]:x[2] + 1] = result[i + len(horizontal)]
A = list(map(list, zip(*A)))
print(*(''.join(x) for x in A), sep='\n')


import itertools
A = [input() for i in range(10)]
(horizontal, vertical) = ([], [])
for lst in (horizontal, vertical):
	for row in range(10):
		for (c, g) in itertools.groupby(range(10), key=lambda x: A[row][x]):
			l = list(g)
			if c == '-' and len(l) > 1:
				lst.append([row, l[0], l[-1]])
	A = list(map(list, zip(*A)))
intersections = [(i, column[0] - row[1], j, row[0] - column[1]) for (i, row) in enumerate(horizontal) for (j, column) in enumerate(vertical) if row[1] <= column[0] <= row[2] and column[1] <= row[0] <= column[2]]
words = input().split(';')
result = None
for l in itertools.permutations(words, len(words)):
	if all((len(l[i]) == horizontal[i][2] - horizontal[i][1] + 1 for i in range(len(horizontal)))) and all((len(l[i + len(horizontal)]) == vertical[i][2] - vertical[i][1] + 1 for i in range(len(vertical)))) and all((l[i[0]][i[1]] == l[i[2] + len(horizontal)][i[3]] for i in intersections)):
		result = l
		break
for (i, x) in enumerate(horizontal):
	A[x[0]][x[1]:x[2] + 1] = result[i]
A = list(map(list, zip(*A)))
for (i, x) in enumerate(vertical):
	A[x[0]][x[1]:x[2] + 1] = result[i + len(horizontal)]
A = list(map(list, zip(*A)))
print(*(''.join(x) for x in A), sep='\n')


import sys

def printarray(arr):
	for i in arr:
		str1 = ''.join(i)
		print(str1)

def insertHorWord(arr, i, j, word):
	w_len = len(word)
	for _i in range(w_len):
		if i + _i >= 10 or (arr[i + _i][j] != '-' and arr[i + _i][j] != word[_i]):
			return 0
	if i + w_len < 10 and arr[i + w_len][j] == '-':
		return 0
	for _i in range(w_len):
		arr[i + _i][j] = word[_i]
	return 1

def insertVerWord(arr, i, j, word):
	w_len = len(word)
	for _j in range(w_len):
		if j + _j >= 10 or (arr[i][j + _j] != '-' and arr[i][j + _j] != word[_j]):
			return 0
	if j + w_len < 10 and arr[i][j + w_len] == '-':
		return 0
	for _j in range(w_len):
		arr[i][j + _j] = word[_j]
	return 1

def insertVer(arr, i, j, word):
	w_len = len(word)
	if j - 1 >= 0 and arr[i][j - 1] == '-':
		return 0
	for _j in range(w_len):
		if j + _j >= 10 or (arr[i][j + _j] != '-' and arr[i][j + _j] != word[_j]):
			return 0
	if j + w_len < 10 and arr[i][j + w_len] == '-':
		return 0
	for _j in range(w_len):
		arr[i][j + _j] = word[_j]
	return 1

def insertHor(arr, i, j, word):
	w_len = len(word)
	if i - 1 >= 0 and arr[i - 1][j] == '-':
		return 0
	for _i in range(w_len):
		if i + _i >= 10 or (arr[i + _i][j] != '-' and arr[i + _i][j] != word[_i]):
			return 0
	if i + w_len < 10 and arr[i + w_len][j] == '-':
		return 0
	for _i in range(w_len):
		arr[i + _i][j] = word[_i]
	return 1

def placeWord(arr, i, j, word):
	if i - 1 >= 0 and arr[i - 1][j] == word[0]:
		if not insertHorWord(arr, i - 1, j, word):
			return 0
		else:
			return 1
	if j - 1 >= 0 and arr[i][j - 1] == word[0]:
		if not insertVerWord(arr, i, j - 1, word):
			return 0
		else:
			return 1
	if i + 1 < 10 and arr[i + 1][j] == '-':
		if not insertHor(arr, i, j, word):
			return 0
		else:
			return 1
	if j + 1 < 10 and arr[i][j + 1] == '-':
		if not insertVer(arr, i, j, word):
			return 0
		else:
			return 1
	return 0

def allUsed(used):
	for i in used:
		if i == 0:
			return 0
	return 1

def solve(arr, words, w, n):
	if w == n and allUsed(used):
		return 1
	backup = arr[:]
	for i in range(10):
		for j in range(10):
			if arr[i][j] == '-' and placeWord(arr, i, j, words[w]):
				used[w] = 1
				if solve(arr, words, w + 1, n):
					return 1
			arr = backup[:]
			used[w] = 0
	return 0
arr = [[0 for j in range(10)] for i in range(10)]
for i in range(10):
	arr[i] = list(input().strip())
words = input().strip().split(';')
n = len(words)
used = []
for i in range(n):
	used.append(0)
u_b = used[:]
word = words.pop(1)
words.insert(3, word)
while solve(arr, words, 0, n) == 0:
	word = words.pop()
	words.insert(0, word)
	used = u_b[:]
	for i in range(10):
		for j in range(10):
			if arr[i][j].isalpha():
				arr[i][j] = '-'
for i in arr:
	str1 = ''.join(i)
	print(str1)


import itertools
A = [input() for i in range(10)]
(horizontal, vertical) = ([], [])
for lst in (horizontal, vertical):
	for row in range(10):
		for (c, g) in itertools.groupby(range(10), key=lambda x: A[row][x]):
			l = list(g)
			if c == '-' and len(l) > 1:
				lst.append([row, l[0], l[-1]])
	A = list(map(list, zip(*A)))
intersections = [(i, column[0] - row[1], j, row[0] - column[1]) for (i, row) in enumerate(horizontal) for (j, column) in enumerate(vertical) if row[1] <= column[0] <= row[2] and column[1] <= row[0] <= column[2]]
words = input().split(';')
result = None
for l in itertools.permutations(words, len(words)):
	if all((len(l[i]) == horizontal[i][2] - horizontal[i][1] + 1 for i in range(len(horizontal)))) and all((len(l[i + len(horizontal)]) == vertical[i][2] - vertical[i][1] + 1 for i in range(len(vertical)))) and all((l[i[0]][i[1]] == l[i[2] + len(horizontal)][i[3]] for i in intersections)):
		result = l
		break
for (i, x) in enumerate(horizontal):
	A[x[0]][x[1]:x[2] + 1] = result[i]
A = list(map(list, zip(*A)))
for (i, x) in enumerate(vertical):
	A[x[0]][x[1]:x[2] + 1] = result[i + len(horizontal)]
A = list(map(list, zip(*A)))
print(*(''.join(x) for x in A), sep='\n')


import itertools
A = [input() for i in range(10)]
(horizontal, vertical) = ([], [])
for lst in (horizontal, vertical):
	for row in range(10):
		for (c, g) in itertools.groupby(range(10), key=lambda x: A[row][x]):
			l = list(g)
			if c == '-' and len(l) > 1:
				lst.append([row, l[0], l[-1]])
	A = list(map(list, zip(*A)))
intersections = [(i, column[0] - row[1], j, row[0] - column[1]) for (i, row) in enumerate(horizontal) for (j, column) in enumerate(vertical) if row[1] <= column[0] <= row[2] and column[1] <= row[0] <= column[2]]
words = input().split(';')
result = None
for l in itertools.permutations(words, len(words)):
	if all((len(l[i]) == horizontal[i][2] - horizontal[i][1] + 1 for i in range(len(horizontal)))) and all((len(l[i + len(horizontal)]) == vertical[i][2] - vertical[i][1] + 1 for i in range(len(vertical)))) and all((l[i[0]][i[1]] == l[i[2] + len(horizontal)][i[3]] for i in intersections)):
		result = l
		break
for (i, x) in enumerate(horizontal):
	A[x[0]][x[1]:x[2] + 1] = result[i]
A = list(map(list, zip(*A)))
for (i, x) in enumerate(vertical):
	A[x[0]][x[1]:x[2] + 1] = result[i + len(horizontal)]
A = list(map(list, zip(*A)))
print(*(''.join(x) for x in A), sep='\n')


from collections import Counter

def solve(grid, words):
	pts = find_starting_pts(grid)
	assert len(words) == len(pts), str(pts)
	assert Counter([len(word) for word in words]) == Counter([pt[2] for pt in pts])
	cross_puzzle(grid, words, pts)

def cross_puzzle(grid, words, pts):
	if len(words) == 0:
		return True
	(r, c, l, v) = pts[0]
	for word in words:
		if len(word) != l:
			continue
		marker = []
		for (w, (cr, cc)) in zip(word, gen_cursor(r, c, l, v)):
			if grid[cr][cc] == '-':
				grid[cr][cc] = w
				marker.append((cr, cc))
			elif grid[cr][cc] != w:
				for (mr, mc) in marker:
					grid[mr][mc] = '-'
				break
		else:
			res = cross_puzzle(grid, words - {word}, pts[1:])
			if res:
				return True
			for (mr, mc) in marker:
				grid[mr][mc] = '-'
	else:
		return False

def gen_cursor(r, c, l, v):
	if v:
		(dr, dc) = (1, 0)
	else:
		(dr, dc) = (0, 1)
	for i in range(l):
		yield (r + dr * i, c + dc * i)

def find_starting_pts(grid):
	pts = []
	vertical = False
	for (r, row) in enumerate(grid):
		dashes = 0
		sc = -1
		for (c, cell) in enumerate(row):
			if cell == '-':
				if sc == -1:
					sc = c
				dashes += 1
			else:
				if dashes >= 2:
					pts += [(r, sc, dashes, vertical)]
				sc = -1
				dashes = 0
		else:
			if dashes >= 2:
				pts += [(r, sc, dashes, vertical)]
			sc = -1
			dashes = 0
	vertical = True
	for (r, row) in enumerate(zip(*grid)):
		dashes = 0
		sc = -1
		for (c, cell) in enumerate(row):
			if cell == '-':
				if sc == -1:
					sc = c
				dashes += 1
			else:
				if dashes >= 2:
					pts += [(sc, r, dashes, vertical)]
				sc = -1
				dashes = 0
		else:
			if dashes >= 2:
				pts += [(sc, r, dashes, vertical)]
			sc = -1
			dashes = 0
	return pts

def print_grid(grid):
	print('\n'.join([''.join(row) for row in grid]))

def main():
	grid = [list(input().strip()) for _ in range(10)]
	words = set(input().strip().split(';'))
	solve(grid, words)
	print_grid(grid)
main()


import copy
NUM_ROWS = 10
NUM_COLS = 10

def printCrossword(crossword):
	for row in range(len(crossword)):
		print(''.join(crossword[row]))

def tryFitting(wordList, crossword, acrossList, downList, currentWord, row, col, acrossFlag):
	length = len(currentWord)
	crossword = copy.deepcopy(crossword)
	acrossList = copy.deepcopy(acrossList)
	downList = copy.deepcopy(downList)
	wordList = copy.deepcopy(wordList)
	if acrossFlag == True:
		for wordIndex in range(length):
			if crossword[row][col + wordIndex] == '-':
				continue
			if crossword[row][col + wordIndex] != currentWord[wordIndex]:
				return None
		for wordIndex in range(length):
			crossword[row][col + wordIndex] = currentWord[wordIndex]
		return recurseSolve(wordList, crossword, acrossList, downList)
	else:
		for wordIndex in range(length):
			if crossword[row + wordIndex][col] == '-':
				continue
			if crossword[row + wordIndex][col] != currentWord[wordIndex]:
				return None
		for wordIndex in range(length):
			crossword[row + wordIndex][col] = currentWord[wordIndex]
		return recurseSolve(wordList, crossword, acrossList, downList)

def recurseSolve(wordList, crossword, acrossList, downList):
	if len(wordList) == 0:
		return crossword
	currentWord = wordList.pop()
	for listIndex in range(len(acrossList)):
		(length, row, col) = acrossList[listIndex]
		if length == len(currentWord):
			newAcross = acrossList[:listIndex] + acrossList[listIndex + 1:]
			solution = tryFitting(wordList, crossword, newAcross, downList, currentWord, row, col, True)
			if solution != None:
				return solution
	for listIndex in range(len(downList)):
		(length, row, col) = downList[listIndex]
		if length == len(currentWord):
			newDown = downList[:listIndex] + downList[listIndex + 1:]
			solution = tryFitting(wordList, crossword, acrossList, newDown, currentWord, row, col, False)
			if solution != None:
				return solution
	return None

def solve(wordList, crossword):
	acrossList = []
	for row in range(NUM_ROWS):
		col = 0
		while col < NUM_COLS:
			if crossword[row][col] == '-':
				startCol = col
				while col < NUM_COLS and crossword[row][col] == '-':
					col += 1
				length = col - startCol
				if length > 1:
					acrossList.append([length, row, startCol])
			col += 1
	downList = []
	for col in range(NUM_COLS):
		row = 0
		while row < NUM_ROWS:
			if crossword[row][col] == '-':
				startRow = row
				while row < NUM_ROWS and crossword[row][col] == '-':
					row += 1
				length = row - startRow
				if length > 1:
					downList.append([length, startRow, col])
			row += 1
	assert len(acrossList) + len(downList) == len(wordList)
	return recurseSolve(wordList, crossword, acrossList, downList)
cword = []
for i in range(NUM_ROWS):
	line = input().strip()
	cword.append(list(line))
wordList = input().strip().split(';')
soln = solve(wordList, cword)
printCrossword(soln)


import itertools
A = [input() for i in range(10)]
(horizontal, vertical) = ([], [])
for lst in (horizontal, vertical):
	for row in range(10):
		for (c, g) in itertools.groupby(range(10), key=lambda x: A[row][x]):
			l = list(g)
			if c == '-' and len(l) > 1:
				lst.append([row, l[0], l[-1]])
	A = list(map(list, zip(*A)))
intersections = [(i, column[0] - row[1], j, row[0] - column[1]) for (i, row) in enumerate(horizontal) for (j, column) in enumerate(vertical) if row[1] <= column[0] <= row[2] and column[1] <= row[0] <= column[2]]
words = input().split(';')
result = None
for l in itertools.permutations(words, len(words)):
	if all((len(l[i]) == horizontal[i][2] - horizontal[i][1] + 1 for i in range(len(horizontal)))) and all((len(l[i + len(horizontal)]) == vertical[i][2] - vertical[i][1] + 1 for i in range(len(vertical)))) and all((l[i[0]][i[1]] == l[i[2] + len(horizontal)][i[3]] for i in intersections)):
		result = l
		break
for (i, x) in enumerate(horizontal):
	A[x[0]][x[1]:x[2] + 1] = result[i]
A = list(map(list, zip(*A)))
for (i, x) in enumerate(vertical):
	A[x[0]][x[1]:x[2] + 1] = result[i + len(horizontal)]
A = list(map(list, zip(*A)))
print(*(''.join(x) for x in A), sep='\n')


import itertools
A = [input() for i in range(10)]
(horizontal, vertical) = ([], [])
for lst in (horizontal, vertical):
	for row in range(10):
		for (c, g) in itertools.groupby(range(10), key=lambda x: A[row][x]):
			l = list(g)
			if c == '-' and len(l) > 1:
				lst.append([row, l[0], l[-1]])
	A = list(map(list, zip(*A)))
intersections = [(i, column[0] - row[1], j, row[0] - column[1]) for (i, row) in enumerate(horizontal) for (j, column) in enumerate(vertical) if row[1] <= column[0] <= row[2] and column[1] <= row[0] <= column[2]]
words = input().split(';')
result = None
for l in itertools.permutations(words, len(words)):
	if all((len(l[i]) == horizontal[i][2] - horizontal[i][1] + 1 for i in range(len(horizontal)))) and all((len(l[i + len(horizontal)]) == vertical[i][2] - vertical[i][1] + 1 for i in range(len(vertical)))) and all((l[i[0]][i[1]] == l[i[2] + len(horizontal)][i[3]] for i in intersections)):
		result = l
		break
for (i, x) in enumerate(horizontal):
	A[x[0]][x[1]:x[2] + 1] = result[i]
A = list(map(list, zip(*A)))
for (i, x) in enumerate(vertical):
	A[x[0]][x[1]:x[2] + 1] = result[i + len(horizontal)]
A = list(map(list, zip(*A)))
print(*(''.join(x) for x in A), sep='\n')


import itertools
A = [input() for i in range(10)]
(horizontal, vertical) = ([], [])
for lst in (horizontal, vertical):
	for row in range(10):
		for (c, g) in itertools.groupby(range(10), key=lambda x: A[row][x]):
			l = list(g)
			if c == '-' and len(l) > 1:
				lst.append([row, l[0], l[-1]])
	A = list(map(list, zip(*A)))
intersections = [(i, column[0] - row[1], j, row[0] - column[1]) for (i, row) in enumerate(horizontal) for (j, column) in enumerate(vertical) if row[1] <= column[0] <= row[2] and column[1] <= row[0] <= column[2]]
words = input().split(';')
result = None
for l in itertools.permutations(words, len(words)):
	if all((len(l[i]) == horizontal[i][2] - horizontal[i][1] + 1 for i in range(len(horizontal)))) and all((len(l[i + len(horizontal)]) == vertical[i][2] - vertical[i][1] + 1 for i in range(len(vertical)))) and all((l[i[0]][i[1]] == l[i[2] + len(horizontal)][i[3]] for i in intersections)):
		result = l
		break
for (i, x) in enumerate(horizontal):
	A[x[0]][x[1]:x[2] + 1] = result[i]
A = list(map(list, zip(*A)))
for (i, x) in enumerate(vertical):
	A[x[0]][x[1]:x[2] + 1] = result[i + len(horizontal)]
A = list(map(list, zip(*A)))
print(*(''.join(x) for x in A), sep='\n')


cw = []
for i in range(10):
	cw.append(list(input()))
words = input().split(';')

def printCW(cw, comment=''):
	if comment != '':
		print('------- ', comment)
	for i in range(10):
		print(''.join(cw[i]))

def insertWord(word, cw, row, col, direction):
	cwMod = [row[:] for row in cw]
	for i in range(len(word)):
		if row >= 10 or col >= 10:
			return (False, None)
		letter = word[i]
		if cwMod[row][col] != '-' and cwMod[row][col] != letter:
			return (False, None)
		cwMod[row][col] = letter
		if direction == 'down':
			row += 1
		else:
			col += 1
	if row < 10 and col < 10 and (cwMod[row][col] == '-'):
		return (False, None)
	return (True, cwMod)

def insertWords(cw, words):
	if len(words) == 0:
		return (True, cw)
	wordsCopy = words[:]
	word = wordsCopy.pop()
	for row in range(10):
		for col in range(10):
			for direction in ['down', 'across']:
				(inserted, cwWord) = insertWord(word, cw, row, col, direction)
				if inserted:
					(foundAll, soln) = insertWords(cwWord, wordsCopy)
					if foundAll:
						return (foundAll, soln)
	return (False, None)
(foundAll, soln) = insertWords(cw, words)
if foundAll:
	printCW(soln)
else:
	print('OOPS')


import sys
import random

def word_fits(index, word, grid, key, is_horizontal):
	new_char_increment = 10 if is_horizontal else 1
	next_char_index = key + index * new_char_increment
	return next_char_index in grid and (grid[next_char_index] == False or grid[next_char_index] == word[index])

def fits_in_grid(grid, word):
	grid_clone = grid.copy()
	characters = [*word]
	keys = list(grid_clone.keys())
	for key in keys:
		if grid_clone[key] != False and grid_clone[key] != characters[0]:
			continue
		h_keys_candidates = [True for i in range(1, len(characters)) if word_fits(i, characters, grid_clone, key, True)]
		v_keys_candidates = [True for i in range(1, len(characters)) if word_fits(i, characters, grid_clone, key, False)]
		direction_index = 10 if len(h_keys_candidates) == len(characters) - 1 else 1
		if len(h_keys_candidates) == len(characters) - 1 or len(v_keys_candidates) == len(characters) - 1:
			for i in range(0, len(characters)):
				next_key = key + i * direction_index
				grid_clone[next_key] = characters[i]
			return grid_clone
	return False

def crosswords(grid, original_grid, words, word_fitted):
	empty_cells = [x for x in list(grid.values()) if x == False]
	if len(empty_cells) == 0:
		return print_grid(grid)
	word_to_try = [word for word in words if word not in word_fitted]
	new_grid = fits_in_grid(grid, word_to_try[0])
	if new_grid:
		crosswords(new_grid, original_grid, word_to_try, word_fitted + word_to_try[:1])
	else:
		new_set = words + word_fitted
		random.shuffle(new_set)
		crosswords(original_grid, original_grid, new_set, [])

def print_grid(grid):
	for i in range(0, 10):
		for ii in range(0, 10):
			if i * 10 + ii in grid:
				sys.stdout.write(grid[i * 10 + ii])
			else:
				sys.stdout.write('+')
			if ii == 9:
				sys.stdout.write('\n')

def main():
	word_grid = {}
	for i in range(0, 10):
		line = input().strip('\n')
		splited_line = [*line]
		for j in range(0, 10):
			if splited_line[j] == '-':
				word_grid[i * 10 + j] = False
	words = input().split(';')
	crosswords(word_grid, word_grid, words, [])
main()


import itertools
A = [input() for i in range(10)]
(horizontal, vertical) = ([], [])
for lst in (horizontal, vertical):
	for row in range(10):
		for (c, g) in itertools.groupby(range(10), key=lambda x: A[row][x]):
			l = list(g)
			if c == '-' and len(l) > 1:
				lst.append([row, l[0], l[-1]])
	A = list(map(list, zip(*A)))
intersections = [(i, column[0] - row[1], j, row[0] - column[1]) for (i, row) in enumerate(horizontal) for (j, column) in enumerate(vertical) if row[1] <= column[0] <= row[2] and column[1] <= row[0] <= column[2]]
words = input().split(';')
result = None
for l in itertools.permutations(words, len(words)):
	if all((len(l[i]) == horizontal[i][2] - horizontal[i][1] + 1 for i in range(len(horizontal)))) and all((len(l[i + len(horizontal)]) == vertical[i][2] - vertical[i][1] + 1 for i in range(len(vertical)))) and all((l[i[0]][i[1]] == l[i[2] + len(horizontal)][i[3]] for i in intersections)):
		result = l
		break
for (i, x) in enumerate(horizontal):
	A[x[0]][x[1]:x[2] + 1] = result[i]
A = list(map(list, zip(*A)))
for (i, x) in enumerate(vertical):
	A[x[0]][x[1]:x[2] + 1] = result[i + len(horizontal)]
A = list(map(list, zip(*A)))
print(*(''.join(x) for x in A), sep='\n')


import copy

def print_mat(mat):
	for row in range(10):
		print(''.join(mat[row]))

def find_places(mat):
	places = []
	for row in range(10):
		items = []
		a = []
		for col in range(10):
			if mat[row][col] is '-':
				a.append((row, col))
			elif len(a) > 1:
				items.append((a, len(a)))
				a = []
			else:
				a = []
		if len(a) > 1:
			items.append((a, len(a)))
		for i in items:
			places.append(i)
	for col in range(10):
		items = []
		a = []
		for row in range(10):
			if mat[row][col] is '-':
				a.append((row, col))
			elif len(a) > 1:
				items.append((a, len(a)))
				a = []
			else:
				a = []
		if len(a) > 1:
			items.append((a, len(a)))
		for i in items:
			places.append(i)
	return places

def isvalid(mat, place, word):
	k = 0
	for i in place[0]:
		if mat[i[0]][i[1]] is '-':
			mat[i[0]][i[1]] = word[k]
			k += 1
		elif mat[i[0]][i[1]] is word[k]:
			k += 1
		else:
			return False
	if k is len(word):
		return True
	else:
		return False

def fill_graph(mat, places, words, p_ind=-1, w_ind=-1):
	if p_ind == -1:
		res = True
	else:
		res = isvalid(mat, places[p_ind], words[w_ind])
	if res:
		if p_ind is not -1:
			places.pop(p_ind)
			words.pop(w_ind)
		if len(places) == 0 and len(words) == 0:
			return mat
		for (w_ind, w) in enumerate(words):
			for (p_ind, p) in enumerate(places):
				if len(w) is not p[1]:
					continue
				else:
					mat_temp = copy.deepcopy(mat)
					res = fill_graph(mat_temp, places.copy(), words.copy(), p_ind, w_ind)
					if res is not None:
						return res
	else:
		return None
mat = []
for row in range(10):
	a = list(input().strip())
	mat.append(a)
words = list(input().split(';'))
places = find_places(mat)
assert len(places) == len(words)
mat = fill_graph(mat, places, words)
print_mat(mat)


import itertools
HOR = 0
VERT = 1

def read_console():
	reading_crossword = True
	array = []
	words = None
	while reading_crossword:
		a_temp = input().strip()
		if a_temp[0] == '+' or a_temp[0] == '-':
			array.append(a_temp)
		else:
			reading_crossword = False
			words = a_temp
	words = words.split(';')
	return (array, words)

def hard_coded_puzzle1():
	s = '+-++++++++\n+-++++++++\n+-++++++++\n+-----++++\n+-+++-++++\n+-+++-++++\n+++++-++++\n++------++\n+++++-++++\n+++++-++++\nLONDON;DELHI;ICELAND;ANKARA'
	array = s.split('\n')[:-1]
	words = s.split('\n')[-1].split(';')
	return (array, words)

def hard_coded_puzzle2():
	s = '+-++++++++\n+-++++++++\n+-------++\n+-++++++++\n+-++++++++\n+------+++\n+-+++-++++\n+++++-++++\n+++++-++++\n++++++++++\nAGRA;NORWAY;ENGLAND;GWALIOR'
	array = s.split('\n')[:-1]
	words = s.split('\n')[-1].split(';')
	return (array, words)
(array, words) = read_console()

def fill_word(word, array, slot):
	if len(word) != slot[2]:
		return False
	start_pos = slot[0]
	dir = slot[1]
	row = start_pos[0]
	col = start_pos[1]
	for i in range(len(word)):
		if array[row][col] not in ('-', word[i]):
			return False
		array[row] = array[row][:col] + word[i] + array[row][col + 1:]
		if dir == HOR:
			col += 1
		else:
			row += 1
	return True

def reset_slot(array, slot, word):
	start_pos = slot[0]
	dir = slot[1]
	row = start_pos[0]
	col = start_pos[1]
	if slot[2] != len(word):
		return
	for i in range(slot[2]):
		if array[row][col] != word[i]:
			return
		array[row] = array[row][:col] + '-' + array[row][col + 1:]
		if dir == HOR:
			col += 1
		else:
			row += 1

def read_slots(rows):
	covered = []
	slots = []
	for row_index in range(len(rows)):
		for col_index in range(len(rows[row_index])):
			cell = rows[row_index][col_index]
			if cell == '-':
				if not (row_index, col_index, HOR) in covered:
					right_index = col_index
					while True:
						if right_index == len(rows[row_index]) or rows[row_index][right_index] != '-':
							if right_index > col_index + 1:
								slot = ((row_index, col_index), HOR, right_index - col_index)
								slots.append(slot)
							break
						covered.append((row_index, right_index, HOR))
						right_index += 1
				if not (row_index, col_index, VERT) in covered:
					down_index = row_index
					while True:
						if down_index == len(rows) or rows[down_index][col_index] != '-':
							if down_index > row_index + 1:
								slot = ((row_index, col_index), VERT, down_index - row_index)
								slots.append(slot)
							break
						covered.append((down_index, col_index, VERT))
						down_index += 1
	return slots

def print_solution(array):
	for row in array:
		print(row)
slots = read_slots(array)

def all_filled(array):
	for row in array:
		for col in row:
			if col == '-':
				return False
	return True

def resolve_crossword_rec(array, words, slots, filled_slots):
	if all_filled(array):
		return True
	else:
		word = words.pop()
		available_slots = list(filter(lambda x: x[2] == len(word) and x not in filled_slots, slots))
		for slot in available_slots:
			if not fill_word(word, array, slot):
				continue
			filled_slots.append(slot)
			if resolve_crossword_rec(array, words, slots, filled_slots):
				return True
			else:
				filled_slots.remove(slot)
				filled_slots.append(slot)
				reset_slot(array, slot, word)
		words.append(word)
		return False

def resolve_iter(array, words):
	slots = read_slots(array)
	word_perms = itertools.permutations(words)
	for perm in word_perms:
		array_copy = array[:]
		matches = True
		for i in range(len(slots)):
			if not fill_word(perm[i], array_copy, slots[i]):
				matches = False
		if matches:
			print_solution(array_copy)

def resolve_crossword(array, words):
	slots = read_slots(array)
	return resolve_crossword_rec(array, words, slots, [])
resolve_iter(array, words)


import itertools
A = [input() for i in range(10)]
(horizontal, vertical) = ([], [])
for lst in (horizontal, vertical):
	for row in range(10):
		for (c, g) in itertools.groupby(range(10), key=lambda x: A[row][x]):
			l = list(g)
			if c == '-' and len(l) > 1:
				lst.append([row, l[0], l[-1]])
	A = list(map(list, zip(*A)))
intersections = [(i, column[0] - row[1], j, row[0] - column[1]) for (i, row) in enumerate(horizontal) for (j, column) in enumerate(vertical) if row[1] <= column[0] <= row[2] and column[1] <= row[0] <= column[2]]
words = input().split(';')
result = None
for l in itertools.permutations(words, len(words)):
	if all((len(l[i]) == horizontal[i][2] - horizontal[i][1] + 1 for i in range(len(horizontal)))) and all((len(l[i + len(horizontal)]) == vertical[i][2] - vertical[i][1] + 1 for i in range(len(vertical)))) and all((l[i[0]][i[1]] == l[i[2] + len(horizontal)][i[3]] for i in intersections)):
		result = l
		break
for (i, x) in enumerate(horizontal):
	A[x[0]][x[1]:x[2] + 1] = result[i]
A = list(map(list, zip(*A)))
for (i, x) in enumerate(vertical):
	A[x[0]][x[1]:x[2] + 1] = result[i + len(horizontal)]
A = list(map(list, zip(*A)))
print(*(''.join(x) for x in A), sep='\n')


import copy

class Crossword(object):
	matrix = []

	def __init__(self, crossList):
		self.matrix = copy.deepcopy(crossList)

	def __str__(self):
		res = ''
		for row in self.matrix:
			res += ''.join(row) + '\n'
		return res

	def clone(self):
		return Crossword(self.matrix)

	def writeWord(self, posTuple, word):
		tempI = posTuple[0]
		tempJ = posTuple[1]
		direction = posTuple[2]
		for c in word:
			self.matrix[tempI][tempJ] = c
			if direction == 'down':
				tempI += 1
			else:
				tempJ += 1

	def findPositions(self, word):
		positions = []
		for i in range(10):
			for j in range(10):
				if self.matrix[i][j] == '-' or self.matrix[i][j] == word[0]:
					length = 0
					tempI = i
					tempJ = j
					while length < len(word) and tempI < 10 and (tempJ < 10) and (self.matrix[tempI][tempJ] == '-' or self.matrix[tempI][tempJ] == word[length]):
						tempJ += 1
						length += 1
					if length == len(word):
						positions.append((i, j, 'left'))
					length = 0
					tempI = i
					tempJ = j
					while length < len(word) and tempI < 10 and (tempJ < 10) and (self.matrix[tempI][tempJ] == '-' or self.matrix[tempI][tempJ] == word[length]):
						tempI += 1
						length += 1
					if length == len(word):
						positions.append((i, j, 'down'))
		return positions

def solve(crossword, words):
	if len(words) == 0:
		return crossword
	for word in words:
		positions = crossword.findPositions(word)
		if len(positions) == 0:
			return None
		newWords = list(words)
		del newWords[newWords.index(word)]
		for p in positions:
			newCross = crossword.clone()
			newCross.writeWord(p, word)
			res = solve(newCross, newWords)
			if res:
				return res
crossStrings = []
for i in range(10):
	crossStrings.append(list(input()))
words = input().split(';')
a = Crossword(crossStrings)
a
print(solve(a, words))


grid = [None] * 11
for a in range(10):
	grid[a] = list(input())
grid[10] = list('++++++++++')
spoint = []
direction = []
size = []
tgrid = []
for a in zip(*grid):
	tgrid.append(a)
tgrid.append(list('++++++++++'))

def visit(pos, orientation):
	if orientation == 0:
		g = grid
	else:
		g = tgrid
	tot = 0
	mx = 0
	point = 0
	for a in range(11):
		if g[a][pos] == '+':
			if tot > 1:
				if orientation == 0:
					spoint.append((point, pos))
					direction.append('d')
				else:
					spoint.append((pos, point))
					direction.append('r')
				size.append(tot)
			tot = 0
		else:
			tot += 1
			if tot == 1:
				point = a
for a in range(10):
	visit(a, 0)
	visit(a, 1)
citis = input().split(';')
csize = []
for a in citis:
	csize.append(len(a))
clen = len(csize)
vector = []
taken = []
for a in range(clen):
	taken.append(False)

def paint(pos):
	(x, y) = spoint[pos]
	direc = direction[pos]
	ln = size[pos]
	city = citis[vector[pos]]
	for a in range(ln):
		if grid[x][y] == '-':
			grid[x][y] = city[a]
		elif grid[x][y] != city[a]:
			return False
		if direc == 'd':
			x += 1
		else:
			y += 1
	return True

def clear(pos):
	(x, y) = spoint[pos]
	direc = direction[pos]
	ln = size[pos]
	for a in range(ln):
		grid[x][y] = '-'
		if direc == 'd':
			x += 1
		else:
			y += 1

def trypaint(n):
	if n == clen:
		for a in range(10):
			print(''.join(grid[a]))
		exit(0)
	if paint(n):
		trypaint(n + 1)
	clear(n)

def search():
	if len(vector) == clen:
		for a in range(clen):
			if size[a] != csize[vector[a]]:
				return
		trypaint(0)
	else:
		for a in range(clen):
			if taken[a]:
				continue
			taken[a] = True
			vector.append(a)
			search()
			taken[a] = False
			vector.pop()
search()


def fill(grid, words, hor, ver):
	if len(words) == 0:
		for li1 in range(10):
			for li2 in range(10):
				print(grid[li1][li2], end='')
			print('')
		return True
	for li1 in range(len(hor)):
		if hor[li1][2] == len(words[0]):
			canfill = True
			for li2 in range(hor[li1][2]):
				if grid[hor[li1][0]][hor[li1][1] + li2] == '-' or grid[hor[li1][0]][hor[li1][1] + li2] == words[0][li2]:
					continue
				else:
					canfill = False
					break
			if canfill == True:
				for li2 in range(hor[li1][2]):
					grid[hor[li1][0]][hor[li1][1] + li2] = words[0][li2]
				word = words[0]
				del words[0]
				hors = hor[li1]
				del hor[li1]
				ret = fill(grid, words, hor, ver)
				if ret == True:
					return True
				else:
					words.insert(0, word)
					hor.insert(li1, hors)
					for li2 in range(hor[li1][2]):
						grid[hor[li1][0]][hor[li1][1] + li2] = '-'
					continue
	for li1 in range(len(ver)):
		if ver[li1][2] == len(words[0]):
			canfill = True
			for li2 in range(ver[li1][2]):
				if grid[ver[li1][0] + li2][ver[li1][1]] == '-' or grid[ver[li1][0] + li2][ver[li1][1]] == words[0][li2]:
					continue
				else:
					canfill = False
					break
			if canfill == True:
				for li2 in range(ver[li1][2]):
					grid[ver[li1][0] + li2][ver[li1][1]] = words[0][li2]
				word = words[0]
				del words[0]
				vers = ver[li1]
				del ver[li1]
				ret = fill(grid, words, hor, ver)
				if ret == True:
					return True
				else:
					words.insert(0, word)
					ver.insert(li1, vers)
					for li2 in range(ver[li1][2]):
						grid[ver[li1][0] + li2][ver[li1][1]] = words[0][li2]
					continue
	return False
grid = [list(input()) for _ in range(10)]
words = [temp for temp in input().strip().split(';')]
hor = []
for li1 in range(10):
	tocontinue = False
	count = 0
	startr = 0
	startc = 0
	for li2 in range(10):
		if grid[li1][li2] == '-' and tocontinue == False:
			tocontinue = True
			startr = li1
			startc = li2
			count += 1
		elif grid[li1][li2] == '-' and tocontinue == True:
			count += 1
		elif grid[li1][li2] == '+' and tocontinue == True:
			tocontinue = False
			hor.append([startr, startc, count])
			count = 0
			startr = 0
			startc = 0
	if tocontinue == True:
		hor.append([startr, startc, count])
ver = []
for li1 in range(10):
	tocontinue = False
	count = 0
	startr = 0
	startc = 0
	for li2 in range(10):
		if grid[li2][li1] == '-' and tocontinue == False:
			tocontinue = True
			startr = li2
			startc = li1
			count += 1
		elif grid[li2][li1] == '-' and tocontinue == True:
			count += 1
		elif grid[li2][li1] == '+' and tocontinue == True:
			tocontinue = False
			ver.append([startr, startc, count])
			count = 0
			startr = 0
			startc = 0
	if tocontinue == True:
		ver.append([startr, startc, count])
li1 = 0
while li1 < len(hor):
	if hor[li1][2] == 1:
		if hor[li1][0] + 1 < 10 and grid[hor[li1][0] + 1][hor[li1][1]] == '-':
			del hor[li1]
		elif hor[li1][0] - 1 >= 0 and grid[hor[li1][0] - 1][hor[li1][1]] == '-':
			del hor[li1]
	else:
		li1 += 1
li1 = 0
while li1 < len(ver):
	if ver[li1][2] == 1:
		if ver[li1][1] + 1 < 10 and grid[ver[li1][0]][ver[li1][1] + 1] == '-':
			del ver[li1]
		elif ver[li1][1] - 1 >= 0 and grid[ver[li1][0]][ver[li1][1] - 1] == '-':
			del ver[li1]
	else:
		li1 += 1
fill(grid, words, hor, ver)


import itertools
A = [input() for i in range(10)]
(horizontal, vertical) = ([], [])
for lst in (horizontal, vertical):
	for row in range(10):
		for (c, g) in itertools.groupby(range(10), key=lambda x: A[row][x]):
			l = list(g)
			if c == '-' and len(l) > 1:
				lst.append([row, l[0], l[-1]])
	A = list(map(list, zip(*A)))
intersections = [(i, column[0] - row[1], j, row[0] - column[1]) for (i, row) in enumerate(horizontal) for (j, column) in enumerate(vertical) if row[1] <= column[0] <= row[2] and column[1] <= row[0] <= column[2]]
words = input().split(';')
result = None
for l in itertools.permutations(words, len(words)):
	if all((len(l[i]) == horizontal[i][2] - horizontal[i][1] + 1 for i in range(len(horizontal)))) and all((len(l[i + len(horizontal)]) == vertical[i][2] - vertical[i][1] + 1 for i in range(len(vertical)))) and all((l[i[0]][i[1]] == l[i[2] + len(horizontal)][i[3]] for i in intersections)):
		result = l
		break
for (i, x) in enumerate(horizontal):
	A[x[0]][x[1]:x[2] + 1] = result[i]
A = list(map(list, zip(*A)))
for (i, x) in enumerate(vertical):
	A[x[0]][x[1]:x[2] + 1] = result[i + len(horizontal)]
A = list(map(list, zip(*A)))
print(*(''.join(x) for x in A), sep='\n')


def check(word, i, l):
	if i[0] == 0:
		old = []
		for j in range(len(word)):
			if l[i[1]][i[2] + j] == '-' or l[i[1]][i[2] + j] == word[j]:
				old = old + [l[i[1]][i[2] + j]]
				l[i[1]][i[2] + j] = word[j]
			else:
				for j in range(len(old)):
					l[i[1]][i[2] + j] = old[j]
				return False
	elif i[0] == 1:
		old = []
		for j in range(len(word)):
			if l[i[1] + j][i[2]] == '-' or l[i[1] + j][i[2]] == word[j]:
				old = old + [l[i[1] + j][i[2]]]
				l[i[1] + j][i[2]] = word[j]
			else:
				for j in range(len(old)):
					l[i[1] + j][i[2]] = old[j]
				return False
	return True

def my(words, space, l):
	slength = len(words[0])
	for i in space:
		if i[3] == slength:
			if check(words[0], i, l):
				if len(words) > 1:
					my(words[1:], space, l)
					if i[0] == 0:
						for j in range(len(words[0])):
							l[i[1]][i[2] + j] = '-'
					elif i[0] == 1:
						for j in range(len(words[0])):
							l[i[1] + j][i[2]] = '-'
				else:
					for p in l:
						print(*p, sep='')
l = []
for i in range(10):
	l.append([c for c in input()])
words = input().split(';')
space = []
for i in range(10):
	c = h = k = 0
	for j in range(10):
		if l[i][j] == '-':
			if c == 0:
				h = i
				k = j
			c += 1
		else:
			if c > 1:
				space.append([0, h, k, c])
			c = k = h = 0
		if c > 1 and j == 9:
			space.append([0, h, k, c])
for i in range(10):
	c = h = k = 0
	for j in range(10):
		if l[j][i] == '-':
			if c == 0:
				h = j
				k = i
			c += 1
		else:
			if c > 1:
				space.append([1, h, k, c])
			c = k = h = 0
		if c > 1 and j == 9:
			space.append([1, h, k, c])
my(words, space, l)


import itertools
A = [input() for i in range(10)]
(horizontal, vertical) = ([], [])
for lst in (horizontal, vertical):
	for row in range(10):
		for (c, g) in itertools.groupby(range(10), key=lambda x: A[row][x]):
			l = list(g)
			if c == '-' and len(l) > 1:
				lst.append([row, l[0], l[-1]])
	A = list(map(list, zip(*A)))
intersections = [(i, column[0] - row[1], j, row[0] - column[1]) for (i, row) in enumerate(horizontal) for (j, column) in enumerate(vertical) if row[1] <= column[0] <= row[2] and column[1] <= row[0] <= column[2]]
words = input().split(';')
result = None
for l in itertools.permutations(words, len(words)):
	if all((len(l[i]) == horizontal[i][2] - horizontal[i][1] + 1 for i in range(len(horizontal)))) and all((len(l[i + len(horizontal)]) == vertical[i][2] - vertical[i][1] + 1 for i in range(len(vertical)))) and all((l[i[0]][i[1]] == l[i[2] + len(horizontal)][i[3]] for i in intersections)):
		result = l
		break
for (i, x) in enumerate(horizontal):
	A[x[0]][x[1]:x[2] + 1] = result[i]
A = list(map(list, zip(*A)))
for (i, x) in enumerate(vertical):
	A[x[0]][x[1]:x[2] + 1] = result[i + len(horizontal)]
A = list(map(list, zip(*A)))
print(*(''.join(x) for x in A), sep='\n')


m = []
for _ in range(10):
	m.append([x for x in input().strip()])
words = input().strip().split(';')

def f(n):
	if n >= len(words):
		return True
	for i in range(len(m)):
		for j in range(len(m[i])):
			if j + len(words[n]) <= len(m[i]) and all((m[i][j + k] in ('-', words[n][k]) for k in range(len(words[n])))) and (j + len(words[n]) == len(m[i]) or m[i][j + len(words[n])] == '+'):
				bkp = []
				for k in range(len(words[n])):
					bkp.append(m[i][j + k])
					m[i][j + k] = words[n][k]
				if f(n + 1):
					return True
				for k in range(len(words[n])):
					m[i][j + k] = bkp[k]
			elif i + len(words[n]) <= len(m) and all((m[i + k][j] in ('-', words[n][k]) for k in range(len(words[n])))) and (i + len(words[n]) == len(m) or m[i + len(words[n])][j] == '+'):
				bkp = []
				for k in range(len(words[n])):
					bkp.append(m[i + k][j])
					m[i + k][j] = words[n][k]
				if f(n + 1):
					return True
				for k in range(len(words[n])):
					m[i + k][j] = bkp[k]
	return False
if f(0):
	for x in m:
		print(*x, sep='')


def can_place_word(grid, word, insertion_pos):
	(R, C, dir) = insertion_pos
	(r, c) = (R, C)
	for i in range(len(word)):
		if dir:
			r = R + i
		else:
			c = C + i
		if r >= len(grid) or c >= len(grid) or grid[r][c] == '+' or (grid[r][c] != '-' and grid[r][c] != word[i]):
			return False
	return True

def place_word(grid, word, insertion_pos):
	(R, C, dir) = insertion_pos
	(r, c) = (R, C)
	for i in range(len(word)):
		if dir:
			r = R + i
		else:
			c = C + i
		grid[r][c] = word[i]

def get_neighbours(grid, insertion_pos):
	(r, c, dir) = insertion_pos
	neighbours = []
	if dir:
		if c > 1:
			neighbours.append((r, c - 1))
		if c < len(grid) - 1:
			neighbours.append((r, c + 1))
	else:
		if r > 1:
			neighbours.append((r - 1, c))
		if r < len(grid) - 1:
			neighbours.append((r + 1, c))
	return neighbours

def has_filled_neighbours(grid, insertion_pos):
	for (r, c) in get_neighbours(grid, insertion_pos):
		if grid[r][c] != '-' and grid[r][c] != '+':
			return True
	return False

def remove_word(grid, word, insertion_pos):
	(R, C, dir) = insertion_pos
	(r, c) = (R, C)
	for i in range(len(word)):
		if dir:
			r = R + i
		else:
			c = C + i
		if not has_filled_neighbours(grid, (r, c, dir)):
			grid[r][c] = '-'

def get_insertion_positions(grid):
	pos = []
	for r in range(len(grid)):
		start = False
		candidate_pos = (0, 0)
		curr_len = 1
		for c in range(len(grid)):
			if not start and grid[r][c] == '-':
				candidate_pos = (r, c)
				start = True
				curr_len = 1
			elif start and (grid[r][c] == '+' or c == len(grid) - 1):
				if curr_len > 1:
					pos.append(candidate_pos + (0,))
				start = False
			elif start and grid[r][c] == '-':
				curr_len += 1
	for c in range(len(grid)):
		start = False
		candidate_pos = (0, 0)
		curr_len = 1
		for r in range(len(grid)):
			if not start and grid[r][c] == '-':
				start = True
				curr_len = 1
				candidate_pos = (r, c)
			elif start and (grid[r][c] == '+' or r == len(grid) - 1):
				if curr_len > 1:
					pos.append(candidate_pos + (1,))
				start = False
			elif start and grid[r][c] == '-':
				curr_len += 1
	return pos

def place(grid, words, insertion_positions=None):
	if not words:
		return True
	if insertion_positions == None:
		insertion_positions = get_insertion_positions(grid)
	if insertion_positions == []:
		return False
	for word in words:
		pos = insertion_positions[0]
		if can_place_word(grid, word, pos):
			place_word(grid, word, pos)
			rem_words = words[:]
			rem_words.remove(word)
			if place(grid, rem_words, insertion_positions[1:]):
				return True
			remove_word(grid, word, pos)
	return False
grid = [list(input()) for _ in range(10)]
words = input().split(';')
place(grid, words)
for line in grid:
	print(''.join(line))


a = list(map(lambda _: list(input().strip()), range(10)))
w = input().split(';')
slots = []
for i in range(10):
	start = 0
	for j in range(10):
		if a[i][j] == '-':
			start += 1
		elif start:
			if start > 1:
				slots.append([start, True, i, j - start])
			start = 0
	if start > 1:
		slots.append([start, True, i, 10 - start])
for i in range(10):
	start = 0
	for j in range(10):
		if a[j][i] == '-':
			start += 1
		elif start:
			if start > 1:
				slots.append([start, False, j - start, i])
			start = 0
	if start > 1:
		slots.append([start, False, 10 - start, i])

def f(n=0):
	if n == len(w):
		return True
	p = w[n]
	n += 1
	c = []
	for slot in slots:
		if slot[0] == len(p):
			slot[0] = 0
			(_, _, x, y) = slot
			comp = True
			if slot[1]:
				for j in range(len(p)):
					if a[x][y + j] == '-':
						a[x][y + j] = p[j]
						c.append((x, y + j))
					elif a[x][y + j] != p[j]:
						comp = False
						break
			else:
				for j in range(len(p)):
					if a[x + j][y] == '-':
						a[x + j][y] = p[j]
						c.append((x + j, y))
					elif a[x + j][y] != p[j]:
						comp = False
						break
			if comp and f(n):
				return True
			for (x, y) in c:
				a[x][y] = '-'
			slot[0] = len(p)
	return False
f()
print(*map(''.join, a), sep='\n')


def word_gaps(crossword):
	down = []
	for i in range(9):
		for j in range(10):
			if crossword[i][j] == '-' and crossword[i + 1][j] == '-':
				if i > 0 and crossword[i - 1][j] == '-':
					continue
				i2 = i + 2
				wordlength = 2
				while i2 < 10 and crossword[i2][j] == '-':
					i2 += 1
					wordlength += 1
				down.append((i, j, wordlength))
	across = []
	for i in range(10):
		for j in range(9):
			if crossword[i][j] == '-' and crossword[i][j + 1] == '-':
				if j > 0 and crossword[i][j - 1] == '-':
					continue
				j2 = j + 2
				wordlength = 2
				while j2 < 10 and crossword[i][j2] == '-':
					j2 += 1
					wordlength += 1
				across.append((i, j, wordlength))
	return (down, across)

def copysans(arr, elem):
	arr2 = list(arr)
	arr2.remove(elem)
	return arr2

def solve(crossword, down, across, words):
	if down + across == []:
		return crossword
	for (i, j, wordlength) in down:
		for w in words:
			if wordlength == len(w):
				valid = True
				for k in range(wordlength):
					if crossword[i + k][j] != '-' and crossword[i + k][j] != w[k]:
						valid = False
						break
				if valid:
					spaces = []
					for k in range(wordlength):
						if crossword[i + k][j] == '-':
							spaces.append(k)
							crossword[i + k][j] = w[k]
					ans = solve(crossword, copysans(down, (i, j, wordlength)), across, copysans(words, w))
					if ans != None:
						return ans
					for k in spaces:
						crossword[i + k][j] = '-'
	for (i, j, wordlength) in across:
		for w in words:
			if wordlength == len(w):
				valid = True
				for k in range(wordlength):
					if crossword[i][j + k] != '-' and crossword[i][j + k] != w[k]:
						valid = False
						break
				if valid:
					spaces = []
					for k in range(wordlength):
						if crossword[i][j + k] == '-':
							spaces.append(k)
							crossword[i][j + k] = w[k]
					ans = solve(crossword, down, copysans(across, (i, j, wordlength)), copysans(words, w))
					if ans != None:
						return ans
					for k in spaces:
						crossword[i][j + k] = '-'
crossword = []
for _ in range(10):
	crossword.append([x for x in input().strip()])
words = input().split(sep=';')
(down, across) = word_gaps(crossword)
ans = solve(crossword, down, across, words)
for x in ans:
	print(''.join(x))


from collections import defaultdict

def solve(Board, Words):
	count = [[None for c in r] for r in Board]
	Starts = defaultdict(list)
	for r in range(len(Board)):
		for c in range(len(Board[0])):
			if Board[r][c] != '+':
				if c == 0 or Board[r][c - 1] == '+':
					j = c
					while j < len(Board[r]) and Board[r][j] != '+':
						count[r][j] = 0
						j += 1
					if j - c > 1:
						Starts[j - c].append((r, c, 'h'))
				if r == 0 or Board[r - 1][c] == '+':
					i = r
					while i < len(Board) and Board[i][c] != '+':
						count[i][c] = 0
						i += 1
					if i - r > 1:
						Starts[i - r].append((r, c, 'v'))
	WordsLen = defaultdict(list)
	for word in Words:
		WordsLen[len(word)].append(word)

	def isValid(word, start):
		(r, c, d) = start
		if d == 'h':
			return all((Board[r][c + j] in ('-', word[j]) for j in range(len(word))))
		else:
			return all((Board[r + i][c] in ('-', word[i]) for i in range(len(word))))

	def putWord(word, start):
		(r, c, d) = start
		if d == 'h':
			for j in range(len(word)):
				Board[r][c + j] = word[j]
				count[r][c + j] += 1
		else:
			for i in range(len(word)):
				Board[r + i][c] = word[i]
				count[r + i][c] += 1

	def removeWord(word, start):
		(r, c, d) = start
		if d == 'h':
			for j in range(len(word)):
				count[r][c + j] -= 1
				if count[r][c + j] == 0:
					Board[r][c + j] = '-'
		else:
			for i in range(len(word)):
				count[r + i][c] -= 1
				if count[r + i][c] == 0:
					Board[r + i][c] = '-'
	stack = []
	while Words:
		word = Words.pop()
		if not stack or word != stack[-1][0]:
			stack.append((word, 0))
			start = Starts[len(word)][0]
			if isValid(word, start):
				putWord(word, start)
			else:
				Words.append(word)
		else:
			(word, i) = stack.pop()
			start = Starts[len(word)][i]
			if isValid(word, start):
				removeWord(word, start)
			i += 1
			if i >= len(Starts[len(word)]):
				Words.append(word)
				Words.append(stack[-1][0])
			else:
				stack.append((word, i))
				start = Starts[len(word)][i]
				if isValid(word, start):
					putWord(word, start)
				else:
					Words.append(word)
	return
Board = [[c for c in input()] for r in range(10)]
Words = list(input().strip().split(';'))
solve(Board, Words)
print('\n'.join((''.join((c for c in r)) for r in Board)))


class Slot:

	def __init__(self, start, length, vertical, taken):
		self.start = start
		self.length = length
		self.vertical = vertical
		self.taken = taken

def main():
	(grid, slots) = read_grid()
	words = set(input().split(';'))
	solve_puzzle(grid, slots, words)
	for row in grid:
		print(''.join(row))

def read_grid():
	rows = []
	for i in range(10):
		row = input()
		rows.append(row)
	row_slots = _get_slots(rows)
	cols = []
	for i in range(10):
		col = ''
		for j in range(10):
			col += rows[j][i]
		cols.append(col)
	col_slots = _get_slots(cols, vertical=True)
	return ([list(row) for row in rows], row_slots + col_slots)

def _get_slots(lines, vertical=False):
	slots = []
	line_num = 0
	for line in lines:
		for occurrence in _slot_occurrences(line):
			(slot_index, slot_length) = occurrence
			if vertical:
				start = (slot_index, line_num)
			else:
				start = (line_num, slot_index)
			slots.append(Slot(start, slot_length, vertical, False))
		line_num += 1
	return slots

def _slot_occurrences(line):
	slots = []
	for slot in line.split('+'):
		slot_length = len(slot)
		if slot_length > 1:
			index = 0
			while index < slot_length:
				index = line.find(slot, index)
				if line == -1:
					break
				slots.append((index, slot_length))
				index += slot_length
	return slots

def solve_puzzle(grid, slots, words):
	if len(words) == 0:
		return True
	for word in words:
		for slot in slots:
			if _can_add(grid, slot, word):
				before = _add(grid, slot, word)
				slot.taken = True
				new_words = set(words)
				new_words.remove(word)
				if solve_puzzle(grid, slots, new_words):
					return True
				_add(grid, slot, before)
				slot.taken = False
	return False

def _can_add(grid, slot, word):
	if slot.taken or len(word) != slot.length:
		return False
	(row, col) = slot.start
	for c in word:
		if not (grid[row][col] == '-' or grid[row][col] == c):
			return False
		(row, col) = _next(row, col, slot.vertical)
	return True

def _add(grid, slot, word):
	before = []
	(row, col) = slot.start
	for c in word:
		before.append(grid[row][col])
		grid[row][col] = c
		(row, col) = _next(row, col, slot.vertical)
	return before

def _next(row, col, vertical):
	if vertical:
		return (row + 1, col)
	else:
		return (row, col + 1)
main()


import itertools
c = [['+'] * 12]
for i in range(10):
	c.append(['+'] + list(input()) + ['+'])
c.append(['+'] * 12)
w = {}
for i in input().split(';'):
	try:
		w[len(i)].append(i)
	except:
		w[len(i)] = [i]
d = {}
for i in range(1, 11):
	for j in range(1, 11):
		if c[i][j] == '-' and c[i + 1][j] == '-' and (c[i - 1][j] == '+'):
			k = i
			d1 = []
			while c[k][j] == '-':
				d1.append((k, j))
				k += 1
			try:
				d[len(d1)].append(d1)
			except:
				d[len(d1)] = [d1]
for i in range(1, 11):
	for j in range(1, 11):
		if c[i][j] == '-' and c[i][j + 1] == '-' and (c[i][j - 1] == '+'):
			k = j
			d1 = []
			while c[i][k] == '-':
				d1.append((i, k))
				k += 1
			try:
				d[len(d1)].append(d1)
			except:
				d[len(d1)] = [d1]
b = {}
for i in range(1, 11):
	for j in range(1, 11):
		if c[i][j] == '-' and (c[i][j + 1] == '-' or c[i][j - 1] == '-') and (c[i - 1][j] == '-' or c[i + 1][j] == '-'):
			d1 = []
			d2 = []
			for j1 in d:
				for k in d[j1]:
					if (i, j) in k:
						if d1 == []:
							d1 = k
						else:
							d2 = k
			b[i, j] = [d1, d2]

def test(a2):
	w2 = {}
	for i in a2:
		for j in i:
			try:
				w2[len(j)].append(j)
			except:
				w2[len(j)] = [j]
	for i in b:
		lis1 = b[i][0]
		lis2 = b[i][1]
		pos1 = lis1.index(i)
		pos2 = lis2.index(i)
		len1 = len(lis1)
		len2 = len(lis2)
		pos3 = d[len1].index(lis1)
		pos4 = d[len2].index(lis2)
		if w2[len1][pos3][pos1] != w2[len2][pos4][pos2]:
			return False
	return True
a = []
for i in w:
	a.append(list(itertools.permutations(w[i])))
a = itertools.product(*a)
for ai in a:
	if test(ai):
		w2 = {}
		for i in ai:
			for j in i:
				try:
					w2[len(j)].append(j)
				except:
					w2[len(j)] = [j]
		for i in d:
			for (j1, j2) in zip(d[i], w2[i]):
				k1 = 0
				for k in j1:
					c[k[0]][k[1]] = j2[k1]
					k1 += 1
		for i in range(1, 11):
			for j in range(1, 11):
				print(c[i][j], end='')
			print()
		break


import itertools
A = [input() for i in range(10)]
(horizontal, vertical) = ([], [])
for lst in (horizontal, vertical):
	for row in range(10):
		for (c, g) in itertools.groupby(range(10), key=lambda x: A[row][x]):
			l = list(g)
			if c == '-' and len(l) > 1:
				lst.append([row, l[0], l[-1]])
	A = list(map(list, zip(*A)))
intersections = [(i, column[0] - row[1], j, row[0] - column[1]) for (i, row) in enumerate(horizontal) for (j, column) in enumerate(vertical) if row[1] <= column[0] <= row[2] and column[1] <= row[0] <= column[2]]
words = input().split(';')
result = None
for l in itertools.permutations(words, len(words)):
	if all((len(l[i]) == horizontal[i][2] - horizontal[i][1] + 1 for i in range(len(horizontal)))) and all((len(l[i + len(horizontal)]) == vertical[i][2] - vertical[i][1] + 1 for i in range(len(vertical)))) and all((l[i[0]][i[1]] == l[i[2] + len(horizontal)][i[3]] for i in intersections)):
		result = l
		break
for (i, x) in enumerate(horizontal):
	A[x[0]][x[1]:x[2] + 1] = result[i]
A = list(map(list, zip(*A)))
for (i, x) in enumerate(vertical):
	A[x[0]][x[1]:x[2] + 1] = result[i + len(horizontal)]
A = list(map(list, zip(*A)))
print(*(''.join(x) for x in A), sep='\n')


from functools import reduce
import copy
ws = []
for _ in range(10):
	ws.append(list(input()))
k = input().split(';')
hash = dict()
hash[''] = k

def fill(m, w):
	if not w:
		return m
	for i in range(10):
		b = -1
		e = -1
		t = False
		for j in range(10):
			if m[i][j] != '+':
				if t:
					continue
				else:
					b = j
					t = True
			elif t:
				e = j
				t = False
				if '-' in m[i][b:e]:
					break
			else:
				continue
		if t:
			e = 10
		if b == -1:
			continue
		l = e - b
		for k in w:
			if len(k) == l:
				f = False
				for h in range(b, e):
					if m[i][h] != '-' and m[i][h] != k[h - b]:
						f = True
						break
				if f:
					continue
				have = True
				z = m[i][b:e]
				m[i][b:e] = k
				g = w[:]
				g.remove(k)
				q = fill(m, g)
				if q:
					return q
				m[i][b:e] = z
	for i in range(10):
		b = -1
		e = -1
		t = False
		for j in range(10):
			if m[j][i] != '+':
				if t:
					continue
				else:
					b = j
					t = True
			elif t:
				e = j
				t = False
				if '-' in [m[h][i] for h in range(b, e)]:
					break
			else:
				continue
		if t:
			e = 10
		if b == -1:
			continue
		l = e - b
		for k in w:
			if len(k) == l:
				f = False
				for h in range(b, e):
					if m[h][i] != '-' and m[h][i] != k[h - b]:
						f = True
						break
				if f:
					continue
				z = [m[h][i] for h in range(b, e)]
				for h in range(b, e):
					m[h][i] = k[h - b]
				g = w[:]
				g.remove(k)
				q = fill(m, g)
				if q:
					return q
				for h in range(b, e):
					m[h][i] = z[h - b]
	return False
t = fill(ws, k)
for i in t:
	print(''.join(i))


import sys
from itertools import *
from math import *
from copy import copy, deepcopy
from collections import *
from queue import Queue
from heapq import heappush, heappop, heapify
from operator import *
from functools import reduce
from string import ascii_lowercase, ascii_uppercase
gi = lambda : int(input())
gis = lambda : list(map(int, input().split()))
gs = lambda : input()
skiplast = lambda x: range(len(x) - 1)
is_even = lambda x: x % 2 == 0
inf = float('inf')
ACROSS = 0
DOWN = 1

def validate_word_placement(placement, blank_grid):
	for (word, ((r, c), direction)) in placement:
		if direction == DOWN:
			for (ch, rr) in zip(word, range(r, r + len(word))):
				if blank_grid[rr][c] != '-' and blank_grid[rr][c] != ch:
					return None
				blank_grid[rr][c] = ch
		else:
			for (ch, cc) in zip(word, range(c, c + len(word))):
				if blank_grid[r][cc] != '-' and blank_grid[r][cc] != ch:
					return None
				blank_grid[r][cc] = ch
	return blank_grid
grid = [list(gs()) for _ in range(10)]
words = gs().split(';')
starts = defaultdict(list)
for (r, c) in product(range(10), range(10)):
	if grid[r][c] == '-':
		for word in words:
			if r + len(word) <= 10 and all((grid[rr][c] == '-' for rr in range(r, r + len(word)))):
				starts[word].append(((r, c), DOWN))
			if c + len(word) <= 10 and all((grid[r][cc] == '-' for cc in range(c, c + len(word)))):
				starts[word].append(((r, c), ACROSS))
paired = [zip(repeat(word), points) for (word, points) in starts.items()]
for placement in product(*paired):
	ans = validate_word_placement(placement, deepcopy(grid))
	if ans is not None:
		break
for row in ans:
	print(*row, sep='')


import re
import copy

def find_length(strings):
	length_dict = {}
	for word in strings:
		word_length = len(word)
		if word_length in length_dict:
			length_dict[word_length].append(word)
		else:
			length_dict[word_length] = [word]
	return length_dict

def find_horizontal_word(grid, row, column):
	horizontal_word = '-'
	start_location = [row, 0]
	for index in range(column - 1, -1, -1):
		if grid[row][index] == '+':
			start_location = [row, index + 1]
			break
		else:
			horizontal_word = grid[row][index] + horizontal_word
	for index in range(column + 1, 10):
		if grid[row][index] == '+':
			break
		else:
			horizontal_word = horizontal_word + grid[row][index]
	return (horizontal_word, start_location)

def find_vertical_word(grid, row, column):
	vertical_word = '-'
	start_location = [0, column]
	for index in range(row - 1, -1, -1):
		if grid[index][column] == '+':
			start_location = [index + 1, column]
			break
		else:
			vertical_word = grid[index][column] + vertical_word
	for index in range(row + 1, 10):
		if grid[index][column] == '+':
			break
		else:
			vertical_word = vertical_word + grid[index][column]
	return (vertical_word, start_location)

def add_horizontally(grid, word, row, column):
	for index in range(column, column + len(word)):
		grid[row][index] = word[index - column]

def solved_puzzle(grid, words, number):
	if words == []:
		return (grid, True)
	for row in range(10):
		for column in range(10):
			if grid[row][column] == '-':
				(horizontal_word, horizontal_start) = find_horizontal_word(grid, row, column)
				(vertical_word, vertical_start) = find_vertical_word(grid, row, column)
				horizontal_word = horizontal_word.replace('-', '.')
				vertical_word = vertical_word.replace('-', '.')
				length_dict = find_length(words)
				choice = []
				horizontal_length = len(horizontal_word)
				if horizontal_length in length_dict:
					for word in length_dict[horizontal_length]:
						match_word = re.match(horizontal_word, word, re.I)
						if match_word != None:
							match_word = match_word.group()
							choice.append([word, 'h'])
				vertical_length = len(vertical_word)
				if vertical_length in length_dict:
					for word in length_dict[vertical_length]:
						match_word = re.match(vertical_word, word, re.I)
						if match_word != None:
							match_word = match_word.group()
							choice.append([word, 'v'])
				if choice == []:
					return (grid, False)
				start_column = horizontal_start[1]
				start_row = vertical_start[0]
				for word_index in range(len(choice)):
					grid_copy = copy.deepcopy(grid)
					words_copy = words[:]
					if choice[word_index][1] == 'h':
						add_horizontally(grid, choice[word_index][0], row, start_column)
					else:
						start_row = vertical_start[0]
						for index in range(start_row, start_row + len(vertical_word)):
							grid[index][column] = choice[word_index][0][index - start_row]
					words.remove(choice[word_index][0])
					(grid, is_solved) = solved_puzzle(grid, words, number + 1)
					if is_solved:
						return (grid, True)
					grid = copy.deepcopy(grid_copy)
					words = copy.deepcopy(words_copy)
grid = []
for i in range(10):
	grid.append(list(input().strip()))
strings = input().strip().split(';')
(grid, is_solved) = solved_puzzle(grid, strings, 1)
if is_solved:
	for row in grid:
		print(''.join(row))


class Slot:

	def __init__(self, start, length, vertical, taken):
		self.start = start
		self.length = length
		self.vertical = vertical
		self.taken = taken

def main():
	(grid, slots) = read_grid()
	words = set(input().split(';'))
	solve_puzzle(grid, slots, words)
	for row in grid:
		print(''.join(row))

def read_grid():
	rows = []
	for i in range(10):
		row = input()
		rows.append(row)
	row_slots = _get_slots(rows)
	cols = []
	for i in range(10):
		col = ''
		for j in range(10):
			col += rows[j][i]
		cols.append(col)
	col_slots = _get_slots(cols, vertical=True)
	return ([list(row) for row in rows], row_slots + col_slots)

def _get_slots(lines, vertical=False):
	slots = []
	line_num = 0
	for line in lines:
		for occurrence in _slot_occurrences(line):
			(slot_index, slot_length) = occurrence
			if vertical:
				start = (slot_index, line_num)
			else:
				start = (line_num, slot_index)
			slots.append(Slot(start, slot_length, vertical, False))
		line_num += 1
	return slots

def _slot_occurrences(line):
	slots = []
	for slot in line.split('+'):
		slot_length = len(slot)
		if slot_length > 1:
			index = 0
			while index < slot_length:
				index = line.find(slot, index)
				if line == -1:
					break
				slots.append((index, slot_length))
				index += slot_length
	return slots

def solve_puzzle(grid, slots, words):
	if len(words) == 0:
		return True
	for word in words:
		for slot in slots:
			if _can_add(grid, slot, word):
				before = _add(grid, slot, word)
				slot.taken = True
				new_words = set(words)
				new_words.remove(word)
				if solve_puzzle(grid, slots, new_words):
					return True
				_add(grid, slot, before)
				slot.taken = False
	return False

def _can_add(grid, slot, word):
	if slot.taken or len(word) != slot.length:
		return False
	(row, col) = slot.start
	for c in word:
		if not (grid[row][col] == '-' or grid[row][col] == c):
			return False
		(row, col) = _next(row, col, slot.vertical)
	return True

def _add(grid, slot, word):
	before = []
	(row, col) = slot.start
	for c in word:
		before.append(grid[row][col])
		grid[row][col] = c
		(row, col) = _next(row, col, slot.vertical)
	return before

def _next(row, col, vertical):
	if vertical:
		return (row + 1, col)
	else:
		return (row, col + 1)
main()


import re
import itertools
from copy import deepcopy
input_grid = []
for i in range(10):
	input_row = input().strip()
	row = []
	for j in input_row:
		row.append(j)
	input_grid.append(row)
temp_grid = deepcopy(input_grid)
string = input().strip().split(';')
string = [word for word in string if re.match('^[A-Z]{1,10}$', word)]
string.sort(key=len, reverse=True)
length = set((len(word) for word in string))
hyphen_positions = []
for i in range(10):
	for j in range(10):
		if input_grid[j][i] == '-':
			hyphen_positions.append([j, i])
local_permutation = []
for each in length:
	words = []
	for w in string:
		if len(w) == each:
			words.append(w)
	permute_words = []
	for i in itertools.permutations(words):
		permute_words.append(i)
	local_permutation.append(permute_words)
join_permutation = []
for i in itertools.product(*local_permutation):
	join_permutation.append(list(itertools.chain(*i)))
final_permutation = []
for i in join_permutation:
	final_permutation.append(sorted(i, key=len, reverse=True))

def insert(word):
	error = True
	for coordinate in hyphen_positions:
		if insert_horizontal(word, coordinate):
			error = False
			for i in range(len(word)):
				temp_grid[coordinate[0]][coordinate[1] + i] = word[i]
			break
		elif insert_vertical(word, coordinate):
			error = False
			for i in range(len(word)):
				temp_grid[coordinate[0] + i][coordinate[1]] = word[i]
			break
	if error:
		return False
	else:
		return True

def insert_horizontal(word, coordinate):
	for i in range(len(word)):
		x = coordinate[0]
		y = coordinate[1] + i
		if y > 9:
			return False
		if temp_grid[x][y] not in ['-', word[i]]:
			return False
	return True

def insert_vertical(word, coordinate):
	for i in range(len(word)):
		x = coordinate[0] + i
		y = coordinate[1]
		if x > 9:
			return False
		if temp_grid[x][y] not in ['-', word[i]]:
			return False
	return True
for permutation in final_permutation:
	error_flag = False
	temp_grid = deepcopy(input_grid)
	for word in permutation:
		if insert(word) == False:
			error_flag = True
			break
	if not error_flag:
		for i in temp_grid:
			print(''.join(i))
		break


import itertools
A = [input() for i in range(10)]
(horizontal, vertical) = ([], [])
for lst in (horizontal, vertical):
	for row in range(10):
		for (c, g) in itertools.groupby(range(10), key=lambda x: A[row][x]):
			l = list(g)
			if c == '-' and len(l) > 1:
				lst.append([row, l[0], l[-1]])
	A = list(map(list, zip(*A)))
intersections = [(i, column[0] - row[1], j, row[0] - column[1]) for (i, row) in enumerate(horizontal) for (j, column) in enumerate(vertical) if row[1] <= column[0] <= row[2] and column[1] <= row[0] <= column[2]]
words = input().split(';')
result = None
for l in itertools.permutations(words, len(words)):
	if all((len(l[i]) == horizontal[i][2] - horizontal[i][1] + 1 for i in range(len(horizontal)))) and all((len(l[i + len(horizontal)]) == vertical[i][2] - vertical[i][1] + 1 for i in range(len(vertical)))) and all((l[i[0]][i[1]] == l[i[2] + len(horizontal)][i[3]] for i in intersections)):
		result = l
		break
for (i, x) in enumerate(horizontal):
	A[x[0]][x[1]:x[2] + 1] = result[i]
A = list(map(list, zip(*A)))
for (i, x) in enumerate(vertical):
	A[x[0]][x[1]:x[2] + 1] = result[i + len(horizontal)]
A = list(map(list, zip(*A)))
print(*(''.join(x) for x in A), sep='\n')


import itertools
A = [input() for i in range(10)]
(horizontal, vertical) = ([], [])
for lst in (horizontal, vertical):
	for row in range(10):
		for (c, g) in itertools.groupby(range(10), key=lambda x: A[row][x]):
			l = list(g)
			if c == '-' and len(l) > 1:
				lst.append([row, l[0], l[-1]])
	A = list(map(list, zip(*A)))
intersections = [(i, column[0] - row[1], j, row[0] - column[1]) for (i, row) in enumerate(horizontal) for (j, column) in enumerate(vertical) if row[1] <= column[0] <= row[2] and column[1] <= row[0] <= column[2]]
words = input().split(';')
result = None
for l in itertools.permutations(words, len(words)):
	if all((len(l[i]) == horizontal[i][2] - horizontal[i][1] + 1 for i in range(len(horizontal)))) and all((len(l[i + len(horizontal)]) == vertical[i][2] - vertical[i][1] + 1 for i in range(len(vertical)))) and all((l[i[0]][i[1]] == l[i[2] + len(horizontal)][i[3]] for i in intersections)):
		result = l
		break
for (i, x) in enumerate(horizontal):
	A[x[0]][x[1]:x[2] + 1] = result[i]
A = list(map(list, zip(*A)))
for (i, x) in enumerate(vertical):
	A[x[0]][x[1]:x[2] + 1] = result[i + len(horizontal)]
A = list(map(list, zip(*A)))
print(*(''.join(x) for x in A), sep='\n')


import itertools
A = [input() for i in range(10)]
(horizontal, vertical) = ([], [])
for lst in (horizontal, vertical):
	for row in range(10):
		for (c, g) in itertools.groupby(range(10), key=lambda x: A[row][x]):
			l = list(g)
			if c == '-' and len(l) > 1:
				lst.append([row, l[0], l[-1]])
	A = list(map(list, zip(*A)))
intersections = [(i, column[0] - row[1], j, row[0] - column[1]) for (i, row) in enumerate(horizontal) for (j, column) in enumerate(vertical) if row[1] <= column[0] <= row[2] and column[1] <= row[0] <= column[2]]
words = input().split(';')
result = None
for l in itertools.permutations(words, len(words)):
	if all((len(l[i]) == horizontal[i][2] - horizontal[i][1] + 1 for i in range(len(horizontal)))) and all((len(l[i + len(horizontal)]) == vertical[i][2] - vertical[i][1] + 1 for i in range(len(vertical)))) and all((l[i[0]][i[1]] == l[i[2] + len(horizontal)][i[3]] for i in intersections)):
		result = l
		break
for (i, x) in enumerate(horizontal):
	A[x[0]][x[1]:x[2] + 1] = result[i]
A = list(map(list, zip(*A)))
for (i, x) in enumerate(vertical):
	A[x[0]][x[1]:x[2] + 1] = result[i + len(horizontal)]
A = list(map(list, zip(*A)))
print(*(''.join(x) for x in A), sep='\n')


import itertools
A = [input() for i in range(10)]
(horizontal, vertical) = ([], [])
for lst in (horizontal, vertical):
	for row in range(10):
		for (c, g) in itertools.groupby(range(10), key=lambda x: A[row][x]):
			l = list(g)
			if c == '-' and len(l) > 1:
				lst.append([row, l[0], l[-1]])
	A = list(map(list, zip(*A)))
intersections = [(i, column[0] - row[1], j, row[0] - column[1]) for (i, row) in enumerate(horizontal) for (j, column) in enumerate(vertical) if row[1] <= column[0] <= row[2] and column[1] <= row[0] <= column[2]]
words = input().split(';')
result = None
for l in itertools.permutations(words, len(words)):
	if all((len(l[i]) == horizontal[i][2] - horizontal[i][1] + 1 for i in range(len(horizontal)))) and all((len(l[i + len(horizontal)]) == vertical[i][2] - vertical[i][1] + 1 for i in range(len(vertical)))) and all((l[i[0]][i[1]] == l[i[2] + len(horizontal)][i[3]] for i in intersections)):
		result = l
		break
for (i, x) in enumerate(horizontal):
	A[x[0]][x[1]:x[2] + 1] = result[i]
A = list(map(list, zip(*A)))
for (i, x) in enumerate(vertical):
	A[x[0]][x[1]:x[2] + 1] = result[i + len(horizontal)]
A = list(map(list, zip(*A)))
print(*(''.join(x) for x in A), sep='\n')