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

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

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

m = A("m")
h = B("h")
j = C("j")
c = A("c")

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

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

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

m = A("m")
h = B("h")
j = C("j")
c = A("c")

m.x = c
m.z = h
h.v = m
h.z = m
j.p = m
c.x = m
c.z = h
assert h.z.x.x.txt == "m"