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

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

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

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

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

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

f.z = h
h.t = f
n.t = f
assert h.t.z.t.txt == "f"