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

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

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

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

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

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

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

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

m.q = l
m.y = j
j.z = g
l.p = j
l.o = g
l.x = g
g.p = j
g.o = l
g.x = l
h.q = l
h.y = j
a.q = g
a.y = j
assert h.q.o.p.z.p.txt == "j"