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

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

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

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

n = A("n")
d = B("d")
h = C("h")
f = D("f")
e = B("e")
j = A("j")
b = C("b")
m = A("m")

n.y = e
d.p = b
d.o = e
d.q = h
h.t = d
f.v = h
e.p = h
e.q = h
e.o = d
j.y = d
b.t = d
m.y = d
assert b.t.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

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

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

n = A("n")
d = B("d")
h = C("h")
f = D("f")
e = B("e")
j = A("j")
b = C("b")
m = A("m")

n.y = e
d.p = b
d.o = e
d.q = h
h.t = d
f.v = h
e.p = h
e.q = h
e.o = d
j.y = d
b.t = d
m.y = d
assert b.t.o.o.o.txt == "e"