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

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

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

m = A("m")
h = B("h")
d = C("d")
b = B("b")

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

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

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

m = A("m")
h = B("h")
d = C("d")
b = B("b")

m.x = h
h.y = d
d.v = m
d.p = m
b.y = d
assert d.v.x.y.txt == "d"