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

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

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

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

class E:
    def __init__(self, txt: str):
        self.v: A = None
        self.txt = txt

f = A("f")
j = B("j")
d = C("d")
c = D("c")
g = E("g")
n = D("n")
h = C("h")
b = C("b")
m = B("m")

f.o = c
j.s = m
d.z = c
d.p = m
c.q = f
g.v = f
n.q = f
h.z = n
h.p = j
b.z = n
b.p = j
m.s = j
assert b.p.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.o: D = None
        self.txt = txt

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

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

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

class E:
    def __init__(self, txt: str):
        self.v: A = None
        self.txt = txt

f = A("f")
j = B("j")
d = C("d")
c = D("c")
g = E("g")
n = D("n")
h = C("h")
b = C("b")
m = B("m")

f.o = c
j.s = m
d.z = c
d.p = m
c.q = f
g.v = f
n.q = f
h.z = n
h.p = j
b.z = n
b.p = j
m.s = j
assert b.p.s.s.s.s.txt == "j"