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

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

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

h = A("h")
l = B("l")
m = C("m")
f = C("f")
c = B("c")

h.p = m
l.z = h
m.u = f
f.u = m
c.z = h
assert l.z.p.u.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.txt = txt

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

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

h = A("h")
l = B("l")
m = C("m")
f = C("f")
c = B("c")

h.p = m
l.z = h
m.u = f
f.u = m
c.z = h
assert l.z.p.u.txt == "f"