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

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

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

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

h.s = m
m.w = a
i.r = f
n.r = f
d.w = h
a.s = f
f.w = a
assert f.w.s.w.s.w.s.w.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

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

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

h.s = m
m.w = a
i.r = f
n.r = f
d.w = h
a.s = f
f.w = a
assert f.w.s.w.s.w.s.w.txt == "a"