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

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

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

j = A("j")
b = B("b")
a = C("a")
m = B("m")
i = A("i")
f = C("f")
n = B("n")
d = C("d")
l = A("l")

j.q = b
j.y = f
b.z = m
a.p = d
m.z = b
i.q = n
i.y = d
f.p = d
n.z = b
d.p = f
l.q = n
l.y = a
assert m.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.y: C = None
        self.txt = txt

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

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

j = A("j")
b = B("b")
a = C("a")
m = B("m")
i = A("i")
f = C("f")
n = B("n")
d = C("d")
l = A("l")

j.q = b
j.y = f
b.z = m
a.p = d
m.z = b
i.q = n
i.y = d
f.p = d
n.z = b
d.p = f
l.q = n
l.y = a
assert m.z.z.z.z.txt == "m"