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

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

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

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

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

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

k.y = f
k.z = h
f.t = h
h.y = f
h.z = k
assert k.y.t.y.txt == "f"