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

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

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

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

f.q = n
f.r = m
h.t = b
h.v = n
n.z = f
n.w = l
l.q = n
l.r = m
e.q = g
e.r = m
m.t = g
m.v = b
d.q = b
d.r = m
a.t = n
a.v = n
g.z = e
g.w = l
b.z = d
b.w = l
assert a.v.w.q.z.q.z.q.z.r.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.r: B = None
        self.txt = txt

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

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

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

f.q = n
f.r = m
h.t = b
h.v = n
n.z = f
n.w = l
l.q = n
l.r = m
e.q = g
e.r = m
m.t = g
m.v = b
d.q = b
d.r = m
a.t = n
a.v = n
g.z = e
g.w = l
b.z = d
b.w = l
assert a.v.w.q.z.q.z.q.z.r.txt == "m"