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

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

m = A("m")
j = B("j")
d = A("d")

m.y = d
m.z = d
j.t = m
d.y = m
d.z = m
assert j.t.z.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.z: A = None
        self.txt = txt

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

m = A("m")
j = B("j")
d = A("d")

m.y = d
m.z = d
j.t = m
d.y = m
d.z = m
assert j.t.z.y.txt == "m"