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

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

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

class D:
    def __init__(self, txt: str):
        self.t: C = None
        self.u: A = None
        self.q: C = None
        self.txt = txt

h = A("h")
d = B("d")
m = C("m")
e = D("e")

h.z = m
h.x = m
d.r = h
d.z = e
m.y = h
e.t = m
e.q = m
e.u = h
assert d.z.u.x.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.x: C = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.t: C = None
        self.u: A = None
        self.q: C = None
        self.txt = txt

h = A("h")
d = B("d")
m = C("m")
e = D("e")

h.z = m
h.x = m
d.r = h
d.z = e
m.y = h
e.t = m
e.q = m
e.u = h
assert d.z.u.x.txt == "m"