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

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

f = A("f")
n = B("n")
m = B("m")

f.z = m
n.y = f
m.y = f
assert f.z.y.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

f = A("f")
n = B("n")
m = B("m")

f.z = m
n.y = f
m.y = f
assert f.z.y.z.txt == "m"