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

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

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

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

l = A("l")
b = B("b")
k = C("k")
d = D("d")
e = C("e")
m = D("m")
j = C("j")

l.s = d
b.t = d
k.s = b
d.r = b
d.w = l
d.u = l
e.s = b
m.r = b
m.w = l
m.u = l
j.s = b
assert j.s.t.r.t.txt == "
class A:
    def __init__(self, txt: str):
        self.s: D = None
        self.txt = txt

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

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

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

l = A("l")
b = B("b")
k = C("k")
d = D("d")
e = C("e")
m = D("m")
j = C("j")

l.s = d
b.t = d
k.s = b
d.r = b
d.w = l
d.u = l
e.s = b
m.r = b
m.w = l
m.u = l
j.s = b
assert j.s.t.r.t.txt == "d"