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

class B:
    def __init__(self, txt: str):
        self.u: C = None
        self.s: D = None
        self.y: D = 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.t: A = None
        self.txt = txt

a = A("a")
h = B("h")
n = C("n")
b = D("b")
m = D("m")

a.s = m
h.u = n
h.s = b
h.y = m
n.p = a
b.t = a
m.t = a
assert n.p.s.t.txt == "
class A:
    def __init__(self, txt: str):
        self.s: D = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.u: C = None
        self.s: D = None
        self.y: D = 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.t: A = None
        self.txt = txt

a = A("a")
h = B("h")
n = C("n")
b = D("b")
m = D("m")

a.s = m
h.u = n
h.s = b
h.y = m
n.p = a
b.t = a
m.t = a
assert n.p.s.t.txt == "a"