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

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

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

n = A("n")
d = B("d")
f = C("f")
a = A("a")
h = C("h")

n.s = f
d.t = n
f.p = n
f.w = a
f.t = d
a.s = f
h.p = n
h.w = a
h.t = d
assert d.t.s.t.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.txt = txt

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

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

n = A("n")
d = B("d")
f = C("f")
a = A("a")
h = C("h")

n.s = f
d.t = n
f.p = n
f.w = a
f.t = d
a.s = f
h.p = n
h.w = a
h.t = d
assert d.t.s.t.txt == "d"