There is a rectangular grid of size $n \times m$. Each cell of the grid is colored black ('0') or white ('1'). The color of the cell $(i, j)$ is $c_{i, j}$. You are also given a map of directions: for each cell, there is a direction $s_{i, j}$ which is one of the four characters 'U', 'R', 'D' and 'L'.

  If $s_{i, j}$ is 'U' then there is a transition from the cell $(i, j)$ to the cell $(i - 1, j)$;  if $s_{i, j}$ is 'R' then there is a transition from the cell $(i, j)$ to the cell $(i, j + 1)$;  if $s_{i, j}$ is 'D' then there is a transition from the cell $(i, j)$ to the cell $(i + 1, j)$;  if $s_{i, j}$ is 'L' then there is a transition from the cell $(i, j)$ to the cell $(i, j - 1)$. 

It is guaranteed that the top row doesn't contain characters 'U', the bottom row doesn't contain characters 'D', the leftmost column doesn't contain characters 'L' and the rightmost column doesn't contain characters 'R'.

You want to place some robots in this field (at most one robot in a cell). The following conditions should be satisfied.

  Firstly, each robot should move every time (i.e. it cannot skip the move). During one move each robot goes to the adjacent cell depending on the current direction.  Secondly, you have to place robots in such a way that there is no move before which two different robots occupy the same cell (it also means that you cannot place two robots in the same cell). I.e. if the grid is "RL" (one row, two columns, colors does not matter there) then you can place two robots in cells $(1, 1)$ and $(1, 2)$, but if the grid is "RLL" then you cannot place robots in cells $(1, 1)$ and $(1, 3)$ because during the first second both robots will occupy the cell $(1, 2)$. 

The robots make an infinite number of moves.

Your task is to place the maximum number of robots to satisfy all the conditions described above and among all such ways, you have to choose one where the number of black cells occupied by robots before all movements is the maximum possible. Note that you can place robots only before all movements.

You have to answer $t$ independent test cases.


-----Input-----

The first line of the input contains one integer $t$ ($1 \le t \le 5 \cdot 10^4$) — the number of test cases. Then $t$ test cases follow.

The first line of the test case contains two integers $n$ and $m$ ($1 < nm \le 10^6$) — the number of rows and the number of columns correspondingly.

The next $n$ lines contain $m$ characters each, where the $j$-th character of the $i$-th line is $c_{i, j}$ ($c_{i, j}$ is either '0' if the cell $(i, j)$ is black or '1' if the cell $(i, j)$ is white).

The next $n$ lines also contain $m$ characters each, where the $j$-th character of the $i$-th line is $s_{i, j}$ ($s_{i, j}$ is 'U', 'R', 'D' or 'L' and describes the direction of the cell $(i, j)$).

It is guaranteed that the sum of the sizes of fields does not exceed $10^6$ ($\sum nm \le 10^6$).


-----Output-----

For each test case, print two integers — the maximum number of robots you can place to satisfy all the conditions described in the problem statement and the maximum number of black cells occupied by robots before all movements if the number of robots placed is maximized. Note that you can place robots only before all movements.


-----Example-----
Input
3
1 2
01
RL
3 3
001
101
110
RLL
DLD
ULL
3 3
000
000
000
RRD
RLD
ULL

Output
2 1
4 3
2 2

```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 = 'import sys\ninput = sys.stdin.readline\n\ndef search(i,j):\n    L=[]\n\n    c=0\n\n    while CHECK[i][j]==1<<30:\n        L.append((i,j))\n        \n        CHECK[i][j]=c\n\n        if MAP2[i][j]=="U":\n            i-=1\n        elif MAP2[i][j]=="D":\n            i+=1\n        elif MAP2[i][j]=="R":\n            j+=1\n        else:\n            j-=1\n\n        c+=1\n\n    if (i,j) in L:\n        x=CHECK[i][j]\n        y=CHECK[L[-1][0]][L[-1][1]]\n        loop=abs(x-y)+1\n\n        for x,y in L:\n            CHECK[x][y]%=loop\n            LOOP[x][y]=loop\n\n    else:\n        loop=LOOP[i][j]\n        c=CHECK[i][j]\n\n        for x,y in L[::-1]:\n            c=(c-1)%loop\n            CHECK[x][y]=c\n            LOOP[x][y]=loop\n\ndef search2(i,j):\n    Q=[(i,j)]\n    ANS=[0]*LOOP[i][j]\n\n    while Q:\n        x,y=Q.pop()\n\n        if USE[x][y]==1:\n            continue\n        \n        USE[x][y]=1\n        if MAP[x][y]=="0":\n            ANS[CHECK[x][y]]=1\n\n        if MAP2[x][y]=="U":\n            Q.append((x-1,y))\n        elif MAP2[x][y]=="D":\n            Q.append((x+1,y))\n        elif MAP2[x][y]=="R":\n            Q.append((x,y+1))\n        else:\n            Q.append((x,y-1))\n\n\n        if 0<=x+1<n and 0<=y<m and MAP2[x+1][y]=="U":\n            Q.append((x+1,y))\n            \n        if 0<=x-1<n and 0<=y<m and MAP2[x-1][y]=="D":\n            Q.append((x-1,y))\n            \n        if 0<=x<n and 0<=y+1<m and MAP2[x][y+1]=="L":\n            Q.append((x,y+1))\n            \n        if 0<=x<n and 0<=y-1<m and MAP2[x][y-1]=="R":\n            Q.append((x,y-1))\n\n    return LOOP[i][j],sum(ANS)\n\n\nt=int(input())\nfor tests in range(t):\n    n,m=list(map(int,input().split()))\n    MAP=[input().strip() for i in range(n)]\n    MAP2=[input().strip() for i in range(n)]\n\n    CHECK=[[1<<30]*m for i in range(n)]\n    LOOP=[[1<<30]*m for i in range(n)]\n\n    for i in range(n):\n        for j in range(m):\n            if CHECK[i][j]==1<<30:\n                search(i,j)\n\n                #print(i,j)\n\n    #print(CHECK)\n    #print(LOOP)\n\n    USE=[[0]*m for i in range(n)]\n\n    ANSM=0\n    ANSC=0\n\n    for i in range(n):\n        for j in range(m):\n            if USE[i][j]==0:\n                x,y=search2(i,j)\n                ANSM+=x\n                ANSC+=y\n    print(ANSM,ANSC)\n                \n            \n    \n    \n'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 13829