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

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

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

f = A("f")
c = B("c")
b = C("b")
k = A("k")
h = C("h")
e = B("e")
g = A("g")
m = C("m")

f.y = e
f.r = c
f.q = m
c.z = h
c.r = e
b.p = f
k.y = c
k.r = c
k.q = b
h.p = g
e.z = m
e.r = c
g.y = c
g.r = e
g.q = b
m.p = g
assert c.z.p.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.r: B = None
        self.q: C = None
        self.txt = txt

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

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

f = A("f")
c = B("c")
b = C("b")
k = A("k")
h = C("h")
e = B("e")
g = A("g")
m = C("m")

f.y = e
f.r = c
f.q = m
c.z = h
c.r = e
b.p = f
k.y = c
k.r = c
k.q = b
h.p = g
e.z = m
e.r = c
g.y = c
g.r = e
g.q = b
m.p = g
assert c.z.p.y.txt == "c"