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

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

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

class D:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

m = A("m")
h = B("h")
b = C("b")
c = D("c")

m.z = b
m.y = c
h.v = c
h.u = b
h.y = b
b.p = m
c.p = h
assert c.p.v.p.v.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.y: D = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

m = A("m")
h = B("h")
b = C("b")
c = D("c")

m.z = b
m.y = c
h.v = c
h.u = b
h.y = b
b.p = m
c.p = h
assert c.p.v.p.v.txt == "c"