My solution to a competitive programming problem (UVA 10189, Minesweeper)
Even in the case of timed contests, you should not sacrifice good practices for brievity. What you gain typing less is lost when debugging or re-reading code.

Using functions to separate logical units of code is the least you should do here as it help isolate, test and assert correctness of each step of the algorithm more easily.

You should take the habbit of starting to write/configure a template in your IDE:

# imports


def main():
    pass


if __name__ == '__main__':
    main()


Here you start by reading the entire input and then extract out tests cases afterwards. I see two issues with that:


you may run into memory issues if the number of tests cases and/or their length is huge;
you do not take advantage of the highly structured input spec.


I would define the following function:

def read_test_case(lines_amount):
    return [input() for _ in range(lines_amount)]


And call it like:

def main():
    while True:
        lines, columns = map(int, input().split())
        if not lines:
            return
        field = read_test_case(lines)
        # ...


You also perform a lot of for ... in range(len(...)) which is rather inefficient. Consider using direct iteration like you do with for field in fields or enumerate if you also need indices:

MINE = '*'


def build_hints(field, lines_max, columns_max):
    def count_mines(x, y):
        count = 0
        for x_offset, y_offset in itertools.product(range(-1,2), repeat=2):
            x_ = x + x_offset
            y_ = y + y_offset
            if x_offset == y_offset == 0 or not (0 &lt;= x_ &lt; columns_max and 0 &lt;= y_ &lt; lines_max):
                continue
            count += field[y_][x_] == MINE
        return count

    return [
        [
            MINE if square == MINE else str(count_mines(x, y))
            for x, square in enumerate(row)
        ]
        for y, row in enumerate(field)
    ]


All what is left is to put all pieces together and print elements. Which lead to:

import itertools


MINE = '*'


def build_hints(field, lines_max, columns_max):
    def count_mines(x, y):
        count = 0
        for x_offset, y_offset in itertools.product(range(-1,2), repeat=2):
            x_ = x + x_offset
            y_ = y + y_offset
            if x_offset == y_offset == 0 or not (0 &lt;= x_ &lt; columns_max and 0 &lt;= y_ &lt; lines_max):
                continue
            count += field[y_][x_] == MINE
        return count

    return [
        [
            MINE if square == MINE else str(count_mines(x, y))
            for x, square in enumerate(row)
        ]
        for y, row in enumerate(field)
    ]


def print_hints(hints):
    for row in hints:
        print(''.join(row))
    print()


def read_test_case(lines_amount):
    return [input() for _ in range(lines_amount)]


def main():
    for test_case in itertools.count(1):
        lines, columns = map(int, input().split())
        if not lines:
            return
        field = read_test_case(lines)
        hints = build_hints(field, lines, columns)
        print('Field #{}:'.format(test_case))
        print_hints(hints)


if __name__ == '__main__':
    main()