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

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

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

b = A("b")
a = B("a")
m = C("m")
c = B("c")
h = A("h")
g = C("g")

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

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

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

b = A("b")
a = B("a")
m = C("m")
c = B("c")
h = A("h")
g = C("g")

b.t = c
a.s = c
a.t = g
m.w = b
m.p = a
c.s = a
c.t = g
h.t = c
g.w = b
g.p = a
assert h.t.t.p.txt == "a"