Recognise a Digit from a Positional Encoding Starting an the origin on an infinite grid, you follow a predetermined path going up (U), down (D), left (L), or right (R). You paint every square you visit, including the square you started at and the square you finish at. Using this method, we can paint the number six using the instructions RRDDLLUUUURR:

The origin is shown as a green star. We call this a positional encoding of the number six. Note that a positional encoding is not unique; the encoding LLUURRDDUULLUURR also encodes the number six with some redundancy:

Note that if you visit a square you've already painted in your path, you leave it as is.
Challenge
Given a positional encoding of one of the digits zero through nine taken as a string, output which digit it encodes.
All digits will be encoded in a \$3\times5\$ format as follows:
#     ###   ###   # #   ### 
#       #     #   # #   #   
#     ###   ###   ###   ### 
#     #       #     #     # 
#     ###   ###     #   ### 

###   ###   ###   ###   ###
#       #   # #   # #   # #
###     #   ###   ###   # #
# #     #   # #     #   # #
###     #   ###   ###   ###

Note that:

The positional encoding given will always map to one of the ten digits given above exactly; the input string is guaranteed to be valid.
The digit will never be mirrored or rotated.
There may be redundancy in the encoding (eg LR).
The square you start at is always painted.

Test Cases
Input                -&gt; Output
DDDD                 -&gt; 1
UUUU                 -&gt; 1
DDUDDUDD             -&gt; 1
DDUUUUDDUUDD         -&gt; 1
LRRDDLLDDRLRR        -&gt; 2
LDDRRLLUURRUULL      -&gt; 2
RRDDLLRRDDLL         -&gt; 3
LLRRUULLRLRRUUDULL   -&gt; 3
LUUDDRRUUDDDD        -&gt; 4
DDLLUUDDRRDD         -&gt; 4
LLDDRRDDLL           -&gt; 5
DLLRRUULLUURRLLRR    -&gt; 5
RRDDLLUUUURR         -&gt; 6
LLUURRDDUULLUURR     -&gt; 6
RRDDLLUURRDDLLUUUURR -&gt; 6
RRDDDD               -&gt; 7
LLRRDDDD             -&gt; 7
LUURRDDDDLLU         -&gt; 8
RUULLUURRDDLLDD      -&gt; 8
RRDDLLUURRDDDDLL     -&gt; 9
DUDLRLLRRUULLRRUULLD -&gt; 9
RRUUUULLDDD          -&gt; 0
UUUUDDDDRRUUUULRDDDD -&gt; 0

Also in list form:
[['DDDD', 1], ['UUUU', 1], ['DDUDDUDD', 1], ['DDUUUUDDUUDD', 1], ['LRRDDLLDDRLRR', 2], ['LDDRRLLUURRUULL', 2], ['RRDDLLRRDDLL', 3], ['LLRRUULLRLRRUUDULL', 3], ['LUUDDRRUUDDDD', 4], ['DDLLUUDDRRDD', 4], ['LLDDRRDDLL', 5], ['DLLRRUULLUURRLLRR', 5], ['RRDDLLUUUURR', 6], ['LLUURRDDUULLUURR', 6], ['RRDDLLUURRDDLLUUUURR', 6], ['RRDDDD', 7], ['LLRRDDDD', 7], ['LUURRDDDDLLU', 8], ['RUULLUURRDDLLDD', 8], ['RRDDLLUURRDDDDLL', 9], ['DUDLRLLRRUULLRRUULLD', 9], ['RRUUUULLDDD', 0], ['UUUUDDDDRRUUUULRDDDD', 0]]

Scoring
Shortest code in bytes wins.
JavaScript (Node.js),  89 ... 77  71 bytes
Saved 6 bytes by using the modulo chain provided by @KjetilS.
s=&gt;Buffer(s).map(c=&gt;o|=p*=4**(c%5)/8,o=p=4**8)|(o/=o&amp;-o)*321%3081%53%11

Try it online!
How?
We take the ASCII code \$c\$ of the direction character modulo \$5\$ to map it to an index in \$\{0,1,2,3\}\$.
For each direction, we update a bit mask \$p\$ by shifting it by a specific amount and mark the bits that are visited in another bit mask \$o\$.
 char. | ASCII | mod 5 | shift
-------+-------+-------+-------
  'U'  |   85  |   0   | &gt;&gt; 3
  'L'  |   76  |   1   | &gt;&gt; 1
  'R'  |   82  |   2   | &lt;&lt; 1
  'D'  |   68  |   3   | &lt;&lt; 3

Conveniently, the shift is equivalent to multiply \$p\$ by:
$$\frac{4^{(c\bmod 5)}}{8}$$
We start with both \$p\$ and \$o\$ set to \$4^8=2^{16}\$. This value is safe because we will never right-shift by more than \$4\times 3 + 2\times 1=14\$ (e.g. with &quot;UUUULL&quot;, which draws a \$7\$, or any other path going from the bottom-right to the top-left corner). Likewise, we will never left-shift by more than \$14\$ and never exceed \$2^{30}\$. So, both \$p\$ and \$o\$ remain 32-bit values.
Because we don't know which cell in the digit was our starting point, we normalize the final value of \$o\$ by removing all trailing zeros:
o /= o &amp; -o

We end up with a unique 15-bit key identifying the digit.
 digit |   binary mask   | decimal
-------+-----------------+---------
   0   | 111101101101111 |  31599
   1   | 001001001001001 |   4681
   2   | 111001111100111 |  29671
   3   | 111100111100111 |  31207
   4   | 100100111101101 |  18925
   5   | 111100111001111 |  31183
   6   | 111101111001111 |  31695
   7   | 100100100100111 |  18727
   8   | 111101111101111 |  31727
   9   | 111100111101111 |  31215

It can be seen as a binary representation of the digit shape rotated by 180°. For instance:
                       100    111
                       100    001
100 100 100 100 111 -&gt; 100 -&gt; 001 -&gt; &quot;7&quot;
                       100    001
                       111    001

We apply the following function to turn it into the expected digit:
$$f(n)=\big(((n\times 321)\bmod 3081)\bmod 53\big)\bmod 11$$