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

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

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

j = A("j")
d = B("d")
c = C("c")
f = B("f")
g = A("g")
k = B("k")
a = C("a")

j.z = g
d.y = a
d.p = g
d.s = c
c.q = f
f.y = a
f.s = a
f.p = g
g.z = j
k.y = a
k.p = g
k.s = c
a.q = f
assert k.p.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.y: C = None
        self.p: A = None
        self.s: C = None
        self.txt = txt

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

j = A("j")
d = B("d")
c = C("c")
f = B("f")
g = A("g")
k = B("k")
a = C("a")

j.z = g
d.y = a
d.p = g
d.s = c
c.q = f
f.y = a
f.s = a
f.p = g
g.z = j
k.y = a
k.p = g
k.s = c
a.q = f
assert k.p.z.z.z.z.z.txt == "j"