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

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

b = A("b")
c = B("c")
i = B("i")
f = B("f")
e = B("e")

b.x = i
c.x = f
c.u = b
i.x = f
i.u = b
f.x = e
f.u = b
e.x = f
e.u = b
assert e.x.x.u.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

b = A("b")
c = B("c")
i = B("i")
f = B("f")
e = B("e")

b.x = i
c.x = f
c.u = b
i.x = f
i.u = b
f.x = e
f.u = b
e.x = f
e.u = b
assert e.x.x.u.x.x.txt == "f"