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

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

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

h = A("h")
i = B("i")
g = C("g")
l = B("l")
b = A("b")
d = B("d")
n = B("n")
e = C("e")
f = C("f")

h.z = b
i.q = h
i.r = b
i.o = l
g.u = l
l.q = h
l.r = b
l.o = n
b.z = h
d.q = b
d.r = h
d.o = n
n.q = h
n.r = b
n.o = i
e.u = d
f.u = d
assert b.z.z.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

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

h = A("h")
i = B("i")
g = C("g")
l = B("l")
b = A("b")
d = B("d")
n = B("n")
e = C("e")
f = C("f")

h.z = b
i.q = h
i.r = b
i.o = l
g.u = l
l.q = h
l.r = b
l.o = n
b.z = h
d.q = b
d.r = h
d.o = n
n.q = h
n.r = b
n.o = i
e.u = d
f.u = d
assert b.z.z.z.z.z.z.txt == "b"