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

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

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

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

d = A("d")
m = B("m")
n = C("n")
f = D("f")
g = C("g")
h = B("h")
l = B("l")

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

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

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

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

d = A("d")
m = B("m")
n = C("n")
f = D("f")
g = C("g")
h = B("h")
l = B("l")

d.o = l
m.p = f
n.r = m
f.p = l
g.r = l
h.p = f
l.p = f
assert n.r.p.p.txt == "l"