private static void BunniesMove(ref char[,] matrix, int rows, int cols, List <Bunny> bunnies)
        {
            List <Bunny> currentbunnies = new List <Bunny>(bunnies);

            foreach (var item in currentbunnies)
            {
                if (item.X - 1 >= 0)
                {
                    if (matrix[item.X - 1, item.Y] != 'B')
                    {
                        matrix[item.X - 1, item.Y] = 'B';
                        Bunny bunny = new Bunny();
                        bunny.X = item.X - 1;
                        bunny.Y = item.Y;
                        bunnies.Add(bunny);
                    }
                }

                if (item.X + 1 < rows)
                {
                    if (matrix[item.X + 1, item.Y] != 'B')
                    {
                        matrix[item.X + 1, item.Y] = 'B';
                        Bunny bunny = new Bunny();
                        bunny.X = item.X + 1;
                        bunny.Y = item.Y;
                        bunnies.Add(bunny);
                    }
                }

                if (item.Y - 1 >= 0)
                {
                    if (matrix[item.X, item.Y - 1] != 'B')
                    {
                        matrix[item.X, item.Y - 1] = 'B';
                        Bunny bunny = new Bunny();
                        bunny.X = item.X;
                        bunny.Y = item.Y - 1;
                        bunnies.Add(bunny);
                    }
                }

                if (item.Y + 1 < cols)
                {
                    if (matrix[item.X, item.Y + 1] != 'B')
                    {
                        matrix[item.X, item.Y + 1] = 'B';
                        Bunny bunny = new Bunny();
                        bunny.X = item.X;
                        bunny.Y = item.Y + 1;
                        bunnies.Add(bunny);
                    }
                }
            }
        }
        static void Main(string[] args)
        {
            List <Bunny> bunnies = new List <Bunny>();

            var RowCols = Console.ReadLine().Split().Select(int.Parse).ToList();

            char[,] matrix = new char[RowCols[0], RowCols[1]];

            int PlayerX = 0;
            int PlayerY = 0;

            for (int i = 0; i < RowCols[0]; i++)
            {
                string line = Console.ReadLine();

                for (int j = 0; j < RowCols[1]; j++)
                {
                    matrix[i, j] = line[j];

                    if (line[j] == 'P')
                    {
                        PlayerX = i;
                        PlayerY = j;
                    }

                    if (line[j] == 'B')
                    {
                        Bunny bunny = new Bunny();
                        bunny.X = i;
                        bunny.Y = j;

                        bunnies.Add(bunny);
                    }
                }
            }

            string moves = Console.ReadLine();

            for (int i = 0; i < moves.Count(); i++)
            {
                PlayerMove(ref PlayerX, ref PlayerY, ref matrix, moves[i], RowCols[0], RowCols[1], bunnies);
                BunniesMove(ref matrix, RowCols[0], RowCols[1], bunnies);
            }
        }