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

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

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

j = A("j")
m = B("m")
d = C("d")
c = C("c")
g = B("g")
l = C("l")
f = C("f")
h = B("h")
a = A("a")

j.q = h
j.z = c
m.p = j
d.y = j
c.y = j
g.p = j
l.y = j
f.y = a
h.p = j
a.q = h
a.z = d
assert j.z.y.q.p.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.z: C = None
        self.txt = txt

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

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

j = A("j")
m = B("m")
d = C("d")
c = C("c")
g = B("g")
l = C("l")
f = C("f")
h = B("h")
a = A("a")

j.q = h
j.z = c
m.p = j
d.y = j
c.y = j
g.p = j
l.y = j
f.y = a
h.p = j
a.q = h
a.z = d
assert j.z.y.q.p.q.txt == "h"