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

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

n = A("n")
h = B("h")
b = A("b")
l = B("l")
d = A("d")
i = A("i")
m = B("m")

n.o = d
h.x = l
b.o = n
l.x = h
d.o = n
i.o = n
m.x = h
assert h.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

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

n = A("n")
h = B("h")
b = A("b")
l = B("l")
d = A("d")
i = A("i")
m = B("m")

n.o = d
h.x = l
b.o = n
l.x = h
d.o = n
i.o = n
m.x = h
assert h.x.x.x.txt == "l"