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

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

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

h = A("h")
b = B("b")
f = C("f")
m = C("m")
e = C("e")
a = A("a")
c = B("c")
d = A("d")
l = B("l")

h.y = m
b.p = l
f.x = b
f.s = b
f.p = m
m.x = c
m.s = l
m.p = f
e.x = c
e.s = b
e.p = f
a.y = m
c.p = b
d.y = f
l.p = b
assert d.y.x.p.p.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.txt = txt

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

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

h = A("h")
b = B("b")
f = C("f")
m = C("m")
e = C("e")
a = A("a")
c = B("c")
d = A("d")
l = B("l")

h.y = m
b.p = l
f.x = b
f.s = b
f.p = m
m.x = c
m.s = l
m.p = f
e.x = c
e.s = b
e.p = f
a.y = m
c.p = b
d.y = f
l.p = b
assert d.y.x.p.p.p.p.p.p.txt == "b"