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

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

f = A("f")
j = B("j")
c = B("c")

f.z = j
j.z = f
c.z = f
assert c.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

f = A("f")
j = B("j")
c = B("c")

f.z = j
j.z = f
c.z = f
assert c.z.z.z.txt == "f"