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

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

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

g = A("g")
m = B("m")
l = C("l")
a = C("a")
k = B("k")
e = A("e")

g.o = m
g.q = l
m.t = g
l.p = a
l.o = g
l.u = m
a.p = l
a.o = g
a.u = m
k.t = e
e.o = k
e.q = a
assert k.t.q.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.q: C = None
        self.txt = txt

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

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

g = A("g")
m = B("m")
l = C("l")
a = C("a")
k = B("k")
e = A("e")

g.o = m
g.q = l
m.t = g
l.p = a
l.o = g
l.u = m
a.p = l
a.o = g
a.u = m
k.t = e
e.o = k
e.q = a
assert k.t.q.o.txt == "g"