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

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

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

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

m = A("m")
k = B("k")
j = C("j")
n = D("n")
h = B("h")

m.u = j
k.s = n
j.s = n
j.y = n
n.p = h
n.y = h
n.w = m
h.s = n
assert j.s.w.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.txt = txt

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

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

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

m = A("m")
k = B("k")
j = C("j")
n = D("n")
h = B("h")

m.u = j
k.s = n
j.s = n
j.y = n
n.p = h
n.y = h
n.w = m
h.s = n
assert j.s.w.u.txt == "j"