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

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

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

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

b.z = k
k.p = j
k.q = g
e.p = d
c.z = k
l.z = k
d.p = f
j.p = d
f.p = j
a.z = k
g.z = k
assert a.z.p.p.p.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

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

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

b.z = k
k.p = j
k.q = g
e.p = d
c.z = k
l.z = k
d.p = f
j.p = d
f.p = j
a.z = k
g.z = k
assert a.z.p.p.p.p.p.p.p.txt == "j"