class A:
    def __init__(self, txt: str):
        self.x: B = 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.s: C = None
        self.txt = txt

b = A("b")
f = B("f")
k = C("k")
c = A("c")
e = C("e")
d = B("d")
h = C("h")

b.x = f
f.p = d
k.s = h
c.x = f
e.s = h
d.p = f
h.s = e
assert b.x.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = 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.s: C = None
        self.txt = txt

b = A("b")
f = B("f")
k = C("k")
c = A("c")
e = C("e")
d = B("d")
h = C("h")

b.x = f
f.p = d
k.s = h
c.x = f
e.s = h
d.p = f
h.s = e
assert b.x.p.p.p.p.txt == "f"