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

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

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

b = A("b")
j = B("j")
f = C("f")
m = B("m")
e = C("e")
l = B("l")
a = B("a")
n = C("n")
g = C("g")
c = A("c")

b.r = c
b.q = c
b.z = c
j.r = c
j.u = b
f.q = l
m.r = b
m.u = c
e.q = l
l.r = b
l.u = b
a.r = b
a.u = b
n.q = a
g.q = a
c.r = b
c.q = b
c.z = b
assert b.z.q.r.q.r.q.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.q: A = None
        self.z: A = None
        self.txt = txt

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

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

b = A("b")
j = B("j")
f = C("f")
m = B("m")
e = C("e")
l = B("l")
a = B("a")
n = C("n")
g = C("g")
c = A("c")

b.r = c
b.q = c
b.z = c
j.r = c
j.u = b
f.q = l
m.r = b
m.u = c
e.q = l
l.r = b
l.u = b
a.r = b
a.u = b
n.q = a
g.q = a
c.r = b
c.q = b
c.z = b
assert b.z.q.r.q.r.q.r.r.txt == "b"