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

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

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

l = A("l")
a = B("a")
h = C("h")
d = A("d")

l.r = h
l.y = d
a.w = l
a.z = h
h.w = a
d.r = h
d.y = l
assert a.z.w.z.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.y: A = None
        self.txt = txt

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

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

l = A("l")
a = B("a")
h = C("h")
d = A("d")

l.r = h
l.y = d
a.w = l
a.z = h
h.w = a
d.r = h
d.y = l
assert a.z.w.z.txt == "h"