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

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

f = A("f")
a = B("a")
d = B("d")

f.o = d
a.x = d
a.z = f
d.x = a
d.z = f
assert d.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

f = A("f")
a = B("a")
d = B("d")

f.o = d
a.x = d
a.z = f
d.x = a
d.z = f
assert d.x.x.x.txt == "a"