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

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

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

b = A("b")
d = B("d")
j = C("j")
e = A("e")
m = C("m")
a = B("a")

b.y = m
d.r = e
j.s = m
j.z = b
e.y = m
m.s = j
m.z = b
a.r = b
assert d.r.y.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.txt = txt

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

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

b = A("b")
d = B("d")
j = C("j")
e = A("e")
m = C("m")
a = B("a")

b.y = m
d.r = e
j.s = m
j.z = b
e.y = m
m.s = j
m.z = b
a.r = b
assert d.r.y.s.s.txt == "m"