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

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

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

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

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

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

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

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

h.z = f
f.x = l
f.z = h
l.p = f
l.u = h
assert h.z.x.u.txt == "h"