class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.t: B = None
        self.w: 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.t: A = None
        self.u: A = None
        self.txt = txt

h = A("h")
b = B("b")
d = C("d")

h.r = d
h.w = d
h.t = b
b.r = h
d.t = h
d.u = h
assert h.r.u.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.t: B = None
        self.w: 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.t: A = None
        self.u: A = None
        self.txt = txt

h = A("h")
b = B("b")
d = C("d")

h.r = d
h.w = d
h.t = b
b.r = h
d.t = h
d.u = h
assert h.r.u.r.txt == "d"