import sys


class Grid:
    def __init__(self, lines):
        lines = map((lambda line: list(line)), lines)
        l = []
        for i in range(len(lines)):
            if i % 2 == 0:
                l.append(intersperse2(lines[i], '+'))
            else:
                l.append(intersperse(lines[i], 'x'))
        l.insert(0, ['0','x','0','x','0','x','0','x','0'])
        l.append(['0','x','0','x','0','x','0','x','0'])
        l = map(lambda x: self._outer(x), l)
        self.grid = l

    def show(self):
        for l in self.grid:
            print l
        return self

    def _outer(self, lis):
        if lis[0] == '0' or lis[0] == '1':
            lis.insert(0, 'x')
        else:
            lis.insert(0, '0')
        if lis[-1] == '0' or lis[-1] == '1':
            lis.append('x')
        else:
            lis.append('0')
        return lis


class Walker:
    def __init__(self, grid, x, y):
        self.grid = grid
        self.x = x
        self.y = y
        self.dir = 'R'

    def walk(self):
        if self.left() == '1':
            return self.to_left()
        elif self.ahead() == '1':
            return self.to_ahead()
        elif self.right() == '1':
            return self.to_right()
        else:
            return self.to_back()

    def left(self):
        x = self.x
        y = self.y
        d = self.dir
        if d == 'R':
            return self.grid.grid[y-1][x]
        elif d == 'L':
            return self.grid.grid[y+1][x]
        elif d == 'U':
            return self.grid.grid[y][x-1]
        else:   # d == 'D'
            return self.grid.grid[y][x+1]

    def ahead(self):
        x = self.x
        y = self.y
        d = self.dir
        if d == 'R':
            return self.grid.grid[y][x+1]
        elif d == 'L':
            return self.grid.grid[y][x-1]
        elif d == 'U':
            return self.grid.grid[y-1][x]
        else:   # d == 'D'
            return self.grid.grid[y+1][x]

    def right(self):
        x = self.x
        y = self.y
        d = self.dir
        if d == 'R':
            return self.grid.grid[y+1][x]
        elif d == 'L':
            return self.grid.grid[y-1][x]
        elif d == 'U':
            return self.grid.grid[y][x+1]
        else:   # d == 'D'
            return self.grid.grid[y][x-1]

    def to_left(self):
        d = self.dir
        if d == 'R':
            self.y -= 2
            self.dir = 'U'
            return 'U'
        elif d == 'L':
            self.y += 2
            self.dir = 'D'
            return 'D'
        elif d == 'U':
            self.x -= 2
            self.dir = 'L'
            return 'L'
        else:   # d == 'D'
            self.x += 2
            self.dir = 'R'
            return 'R'

    def to_ahead(self):
        d = self.dir
        if d == 'R':
            self.x += 2
            return 'R'
        elif d == 'L':
            self.x -= 2
            return 'L'
        elif d == 'U':
            self.y -= 2
            return 'U'
        else:   # d == 'D'
            self.y += 2
            return 'D'

    def to_right(self):
        d = self.dir
        if d == 'R':
            self.y += 2
            self.dir = 'D'
            return 'D'
        elif d == 'L':
            self.y -= 2
            self.dir = 'U'
            return 'U'
        elif d == 'U':
            self.x += 2
            self.dir = 'R'
            return 'R'
        else:   # d == 'D'
            self.x -= 2
            self.dir = 'L'
            return 'L'

    def to_back(self):
        d = self.dir
        if d == 'R':
            self.x -= 2
            self.dir = 'L'
            return 'L'
        elif d == 'L':
            self.x += 2
            self.dir = 'R'
            return 'R'
        elif d == 'U':
            self.y += 2
            self.dir = 'D'
            return 'D'
        else:   # d == 'D'
            self.y -= 2
            self.dir = 'U'
            return 'U'



def intersperse(lis, s):
    r = []
    for a in lis:
        r.append(a)
        r.append(s)
    r.pop()
    return r

def intersperse2(lis, s):
    r = []
    for a in lis:
        r.append(s)
        r.append(a)
    r.append(s)
    return r



lines = sys.stdin.readlines()
lines = map(lambda x: x.rstrip("\r\n"), lines)
grid = Grid(lines)
walker = Walker(grid, 1, 1)
path = []
while True:
    path.append(walker.walk())
    if (walker.x, walker.y) == (1,1):
        break
print ''.join(path)

Measured memory_bytes: 4544