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

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

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

c = A("c")
k = B("k")
i = C("i")
m = C("m")
e = B("e")
h = B("h")
g = A("g")
d = B("d")

c.o = m
k.q = c
k.y = m
i.z = g
m.z = g
e.q = g
e.y = i
h.q = g
h.y = m
g.o = m
d.q = c
d.y = i
assert k.q.o.z.o.z.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.txt = txt

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

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

c = A("c")
k = B("k")
i = C("i")
m = C("m")
e = B("e")
h = B("h")
g = A("g")
d = B("d")

c.o = m
k.q = c
k.y = m
i.z = g
m.z = g
e.q = g
e.y = i
h.q = g
h.y = m
g.o = m
d.q = c
d.y = i
assert k.q.o.z.o.z.txt == "g"