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

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

m = A("m")
l = B("l")
e = A("e")
f = A("f")
d = A("d")

m.x = d
l.y = f
e.x = f
f.x = e
d.x = f
assert e.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

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

m = A("m")
l = B("l")
e = A("e")
f = A("f")
d = A("d")

m.x = d
l.y = f
e.x = f
f.x = e
d.x = f
assert e.x.x.x.x.txt == "e"