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

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

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

m = A("m")
c = B("c")
d = C("d")

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

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

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

m = A("m")
c = B("c")
d = C("d")

m.p = d
m.y = c
c.p = m
c.z = d
c.v = d
d.x = c
assert c.z.x.z.txt == "d"