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

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

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

a = A("a")
g = B("g")
b = C("b")
m = B("m")
k = C("k")
d = C("d")
c = A("c")
h = A("h")
n = C("n")

a.p = k
g.o = c
g.p = a
g.t = m
b.q = m
m.o = a
m.p = a
m.t = g
k.q = g
d.q = g
c.p = d
h.p = b
n.q = m
assert h.p.q.t.o.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.txt = txt

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

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

a = A("a")
g = B("g")
b = C("b")
m = B("m")
k = C("k")
d = C("d")
c = A("c")
h = A("h")
n = C("n")

a.p = k
g.o = c
g.p = a
g.t = m
b.q = m
m.o = a
m.p = a
m.t = g
k.q = g
d.q = g
c.p = d
h.p = b
n.q = m
assert h.p.q.t.o.txt == "c"