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

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

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

l = A("l")
h = B("h")
i = C("i")
m = A("m")
d = B("d")

l.y = m
l.o = d
h.y = l
i.r = l
m.y = l
m.o = h
d.y = m
assert h.y.y.o.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.o: B = None
        self.txt = txt

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

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

l = A("l")
h = B("h")
i = C("i")
m = A("m")
d = B("d")

l.y = m
l.o = d
h.y = l
i.r = l
m.y = l
m.o = h
d.y = m
assert h.y.y.o.y.txt == "l"