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

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

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

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

f.z = b
m.p = a
m.q = f
m.v = n
j.x = m
j.r = n
a.p = m
a.q = b
a.v = d
d.x = m
d.r = j
b.z = f
g.z = f
n.x = m
n.r = d
assert n.r.x.q.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.p: B = None
        self.q: A = None
        self.v: C = None
        self.txt = txt

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

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

f.z = b
m.p = a
m.q = f
m.v = n
j.x = m
j.r = n
a.p = m
a.q = b
a.v = d
d.x = m
d.r = j
b.z = f
g.z = f
n.x = m
n.r = d
assert n.r.x.q.z.z.z.z.z.txt == "b"