#!/usr/bin/env python
import collections

Grid = collections.namedtuple('Grid', 'width,height,data')


def read_grid():
    width, height = map(int, raw_input().split())
    data = []
    for y in xrange(height):
        line = raw_input()
        assert len(line) >= width
        data.extend(line[:width])
    return Grid(width, height, data)


def do_infection(grid, init_x, init_y):
    width, height, data = grid
    outbreaks = set()
    pending_infections = collections.deque([init_y * width + init_x])
    while pending_infections:
        pos = pending_infections.popleft()
        cell = data[pos]
        if cell in 'ABC':
            data[pos] = chr(ord(cell) + 1)
        elif cell == 'D' and pos not in outbreaks:
            y, x = divmod(pos, width)
            if y > 0:
                pending_infections.append(pos - width)
            if y + 1 < height:
                pending_infections.append(pos + width)
            if x > 0:
                pending_infections.append(pos - 1)
            if x + 1 < width:
                pending_infections.append(pos + 1)
            outbreaks.add(pos)


def print_grid(grid):
    for idx in xrange(0, grid.width * grid.height, grid.width):
        print ''.join(grid.data[idx:idx + grid.width])


def main():
    num_cases = input()
    for case_num in xrange(num_cases):
        grid = read_grid()
        num_events = input()
        for event_num in xrange(num_events):
            x, y = map(int, raw_input().split())
            do_infection(grid, x, y)
        print_grid(grid)

main()