Mandarin chinese
, Russian and Vietnamese as well.
You are given a grid with $n$ rows and $m$ columns. Each cell of this grid can either be empty or it contains one particle. It can never contain more than one particle. Let's denote the cell in the $i$-th row and $j$-th column by $(i, j)$, with the top left corner being $(0, 0)$. From a cell $(i, j)$, a particle could move in one of the following four directions:
- to the left, i.e. to the cell $(i, j - 1)$
- to the right, i.e. to the cell $(i, j + 1)$
- up, i.e. to the cell $(i - 1, j)$
- down, i.e. to the cell $(i + 1, j)$
It is not possible for a particle to move to a cell that already contains a particle or to a cell that does not exist (leave the grid).
It is possible to apply a force in each of these directions. When a force is applied in a given direction, all particles will simultaneously start moving in this direction as long as it is still possible for them to move.
You are given a sequence of forces. Each subsequent force is applied only after all particles have stopped moving. Determine which cells of the grid contain particles after all forces from this sequence are applied in the given order.

-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
- The first line of each test case contains two space-separated integers $n$ and $m$.
- $n$ lines describing the initial grid follow. For each $i$ ($1 \le i \le n$), the $i$-th of these lines contains a binary string with length $m$ describing the $i$-th row of the grid. For each $j$ ($1 \le j \le m$), if the $j$-th character of this string is '1', then the cell $(i, j)$ contains a particle, and if it is '0', then the cell $(i, j)$ is empty.
- The last line contains a single string $S$ describing the sequence of applied forces. Each character of this string corresponds to applying a force in some direction; forces applied in the directions left, right, up, down correspond to characters 'L', 'R', 'U', 'D' respectively.

-----Output-----
For each test case, print $n$ lines each containing a binary string of length $m$, describing the resulting grid (after all the forces are applied) in the same format as the input grid.

-----Constraints-----
- $1 \le T \le 200$
- $1 \le n, m \le 100$
- $1 \le |S| \le 2 \cdot 10^4$

-----Subtasks-----
Subtaks #1 (30 points):
- $1 \le T \le 10$
- $1 \le n, m \le 10$
- $1 \le |S| \le 100$
Subtask #2 (70 points): Original constraints

-----Example Input-----
3
4 4
1010
0010
1001
0100
LRDU
4 3
000
010
001
101
LRL
3 2
01
10
00
D

-----Example Output-----
0011
0011
0001
0001
000
100
100
110
00
00
11

-----Explanation-----
Example case 1: The initial grid is:
1010
0010
1001
0100

After applying the first force (in the direction "L", i.e. to the left), the grid is:
1100
1000
1100
1000

After applying the second force (in the direction "R"), the grid is:
0011
0001
0011
0001

After applying the third force (in the direction "D"), the grid is:
0001
0001
0011
0011

After applying the fourth force (in the direction "U"), the final grid is:
0011
0011
0001
0001

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = "def left(list1):\n for i in range(len(list1)):\n  list2=sorted(list1[i])\n  list2.reverse()\n  list1[i]=list2\ndef right(list1):\n for i in range(len(list1)):\n  list2=sorted(list1[i])\n  list1[i]=list2\ndef up(list1):\n for i in range(len(list1[0])):\n  list2=[]\n  for j in range(len(list1)):\n   list2.append(list1[j][i])\n  list2.sort()\n  list2.reverse()\n  for j in range(len(list1)):\n   list1[j][i]=list2[j] \ndef down(list1):\n for i in range(len(list1[0])):\n  list2=[]\n  for j in range(len(list1)):\n   list2.append(list1[j][i])\n  list2.sort()\n  for j in range(len(list1)):\n   list1[j][i]=list2[j]\n\ntest_case=int(input())\nresult=[]\nfor i in range(test_case):\n [n,m]=list(map(int,input().split()))\n list1=[]\n for i in range(n):\n  y=list(input())\n  str2=' '.join(y)\n  list1.append(list(map(int,str2.split())))\n op=list(input())\n for i in range(len(op)):\n  if op[i]=='L':\n   left(list1)\n  if op[i]=='R':\n   right(list1)\n  if op[i]=='D':\n   down(list1)\n  if op[i]=='U':\n   up(list1)\n result.append(list1)\nfor char in result:\n for el in char:\n  print(''.join(list(map(str,el))))"
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 14233