using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        var hw = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var h = hw[0];
        var w = hw[1];
        var board = Enumerable.Repeat(0, hw[0]).Select(_ => Console.ReadLine().ToArray()).ToArray();

        var game = new Game(h, w, board);

        //Console.WriteLine(game.ToDebugString());
        //Console.WriteLine();

        game.Proceed();

        //Console.WriteLine(game.ToDebugString());
        //Console.WriteLine();

        int q = int.Parse(Console.ReadLine());
        for (int i = 0; i < q; i++)
        {
            var xy = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var x = xy[0];
            var y = xy[1];
            y = h - y - 1;
            game.Rotate(x, y);

            //Console.WriteLine(game.ToDebugString());
            //Console.WriteLine();

            game.Proceed();

            //Console.WriteLine(game.ToDebugString());
            //Console.WriteLine();
        }

        Console.WriteLine(game.ToString());
    }
}

class Game
{
    public int Height;
    public int Width;
    public char[][] Board;
    public Game(int h, int w, char[][] board)
    {
        Height = h;
        Width = w;
        Board = board;
    }
    public char this[int y, int x]
    {
        get 
        {
            if (y < 0 || Height <= y || x < 0 || Width <= x) return '.';
            return Board[y][x];
        }
    }

    int[][][] neighborInds = new[]
    {
        new []
        {
            new[] { 0, +1 },
            new[] { +1, 0 },
            new[] { 0, -1 },
            new[] { -1, -1 },
            new[] { -1, 0 },
            new[] { -1, +1 },
        },
        new []
        {
            new[] { +1, +1 },
            new[] { +1, 0 },
            new[] { +1, -1 },
            new[] { 0, -1 },
            new[] { -1, 0 },
            new[] { 0, +1 },
        },
    };

    public void Rotate(int x, int y)
    {
        try
        {
            var inds = neighborInds[x % 2];
            Rotate(
                ref Board[y + inds[5][0]][x + inds[5][1]],
                ref Board[y + inds[4][0]][x + inds[4][1]],
                ref Board[y + inds[3][0]][x + inds[3][1]],
                ref Board[y + inds[2][0]][x + inds[2][1]],
                ref Board[y + inds[1][0]][x + inds[1][1]],
                ref Board[y + inds[0][0]][x + inds[0][1]]
            );
        }
        catch { }
    }
    private void Rotate(ref char a, ref char b, ref char c, ref char d, ref char e, ref char f)
    {
        var tmp = a;
        a = b;
        b = c;
        c = d;
        d = e;
        e = f;
        f = tmp;
    }

    public void Proceed() { while (Cycle()) ; }

    private bool Cycle()
    {
        bool moved = false;

        while (true)
        {
            bool curMoved = false;
            for (int y = Height - 2; y >= 0; y--)
            {
                for (int x = 0; x < Width; x++)
                {
                    if (this[y, x] == '.') continue;
                    if (neighborInds[x % 2].Take(3).All(ind => this[y + ind[0], x + ind[1]] == '.'))
                    {
                        curMoved = true;
                        moved = true;
                        Board[y + 1][x] = Board[y][x];
                        Board[y][x] = '.';
                    }
                }
            }
            if (!curMoved) break;

            //Console.WriteLine(ToDebugString());
            //Console.WriteLine();
        }

        bool[][] flag = Enumerable.Repeat(0, Height).Select(_ => new bool[Width]).ToArray();

        for (int y = 0; y < Height; y++)
        {
            for (int x = 0; x < Width; x++)
            {
                var color = this[y, x];
                if (color == '.') continue;
                var count = neighborInds[x % 2].Count(ind => color == this[y + ind[0], x + ind[1]]);
                if (count < 2) continue;
                flag[y][x] = true;
                foreach (var ind in neighborInds[x % 2])
                {
                    if (color == this[y + ind[0], x + ind[1]])
                    {
                        flag[y + ind[0]][x + ind[1]] = true;
                    }
                }
            }
        }

        for (int y = 0; y < Height; y++)
        {
            for (int x = 0; x < Width; x++)
            {
                if (flag[y][x])
                {
                    moved = true;
                    Board[y][x] = '.';
                }
            }
        }

        return moved;
    }

    public override string ToString()
    {
        return string.Join("\n", Board.Select(x => string.Join("", x)));
    }

    public string ToDebugString()
    {
        return string.Join("\n", Board.Select(x => $" {string.Join("   ", x.Where((_, y) => y % 2 == 0))}\n   {string.Join("   ", x.Where((_, y) => y % 2 == 1))}"));
    }
}



Measured memory_bytes: 22748