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

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

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

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

n.z = f
g.x = n
g.v = n
g.r = n
l.p = n
b.p = n
e.x = n
e.v = n
e.r = n
m.x = n
m.v = n
m.r = n
f.p = n
assert f.p.z.p.z.p.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.txt = txt

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

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

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

n.z = f
g.x = n
g.v = n
g.r = n
l.p = n
b.p = n
e.x = n
e.v = n
e.r = n
m.x = n
m.v = n
m.r = n
f.p = n
assert f.p.z.p.z.p.z.txt == "f"