{$Q+,R+}
uses
	testlib, sysutils;

var
	ja, pa: string;
	i, l, n: longint;

function compress(s: string): string;
begin
	if length(s) < 50 then
		compress := s
	else
		compress := copy(s, 1, 25) + '..' + copy(s, length(s) - 24, 25);
end;

begin
	ja := ans.readstring;
	pa := ouf.readstring;

	n := inf.readlongint;

	for i := 1 to length(pa) do
		if not (pa[i] in ['0'..'9']) then
			quit(_pe, 'invalid character in answer');

	for i := 1 to length(pa) do
		if not (pa[i] in ['1'..char(ord('0') + n)]) then
			quit(_wa, format('invalid digit: "%s" in answer', [pa[i]]));

	if length(ja) <> length(pa) then
		quit(_wa, format('wrong length, expected: %d, found: %d', [length(ja), length(pa)]));

	l := length(ja);
    for i := 1 to l do
    	if ja[i] <> pa[i] then
    		quit(_wa, format('digit %d wrong, expected: %s, found: %s', [i, ja[i], pa[i]]));

    ja := compress(ja);
    quit(_ok, ja);
end.
