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

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

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

h = A("h")
a = B("a")
k = C("k")
m = C("m")
g = B("g")

h.w = a
a.s = h
a.r = m
k.p = h
m.p = h
g.s = h
g.r = m
assert h.w.s.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

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

h = A("h")
a = B("a")
k = C("k")
m = C("m")
g = B("g")

h.w = a
a.s = h
a.r = m
k.p = h
m.p = h
g.s = h
g.r = m
assert h.w.s.w.txt == "a"