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

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

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

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

b = A("b")
m = B("m")
d = C("d")
l = D("l")
h = D("h")

b.t = m
m.o = d
d.r = h
l.p = d
l.w = d
h.p = d
h.w = d
assert m.o.r.w.r.w.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

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

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

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

b = A("b")
m = B("m")
d = C("d")
l = D("l")
h = D("h")

b.t = m
m.o = d
d.r = h
l.p = d
l.w = d
h.p = d
h.w = d
assert m.o.r.w.r.w.txt == "d"