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

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

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

d = A("d")
m = B("m")
a = C("a")

d.y = m
m.o = d
m.r = d
a.z = d
assert d.y.r.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

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

d = A("d")
m = B("m")
a = C("a")

d.y = m
m.o = d
m.r = d
a.z = d
assert d.y.r.y.txt == "m"