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

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

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

h = A("h")
a = B("a")
m = C("m")

h.p = m
h.x = a
a.z = m
m.x = h
assert m.x.p.x.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.x: B = None
        self.txt = txt

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

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

h = A("h")
a = B("a")
m = C("m")

h.p = m
h.x = a
a.z = m
m.x = h
assert m.x.p.x.txt == "h"