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

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

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

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

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

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

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

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

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

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

n.s = c
i.r = n
m.r = n
c.u = h
h.r = n
assert h.r.s.u.txt == "h"