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

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

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

j = A("j")
c = B("c")
a = C("a")
d = C("d")

j.w = c
c.r = a
a.w = d
a.s = j
a.y = c
d.w = a
d.s = j
d.y = c
assert c.r.y.r.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

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

j = A("j")
c = B("c")
a = C("a")
d = C("d")

j.w = c
c.r = a
a.w = d
a.s = j
a.y = c
d.w = a
d.s = j
d.y = c
assert c.r.y.r.txt == "a"