class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.y: B = None
        self.r: A = None
        self.txt = txt

b = A("b")
c = B("c")
a = A("a")
n = B("n")
i = B("i")
l = B("l")

b.y = n
c.y = l
c.r = b
a.y = l
n.y = i
n.r = b
i.y = l
i.r = b
l.y = i
l.r = b
assert a.y.y.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.y: B = None
        self.r: A = None
        self.txt = txt

b = A("b")
c = B("c")
a = A("a")
n = B("n")
i = B("i")
l = B("l")

b.y = n
c.y = l
c.r = b
a.y = l
n.y = i
n.r = b
i.y = l
i.r = b
l.y = i
l.r = b
assert a.y.y.y.y.y.txt == "l"