class A:
    def __init__(self, txt: str):
        self.s: D = None
        self.txt = txt

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

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

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

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

m.s = h
c.z = m
n.x = h
n.o = m
n.z = c
n.r = c
h.x = n
h.s = c
assert n.z.z.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: D = None
        self.txt = txt

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

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

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

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

m.s = h
c.z = m
n.x = h
n.o = m
n.z = c
n.r = c
h.x = n
h.s = c
assert n.z.z.s.txt == "h"