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

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

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

a = A("a")
n = B("n")
g = C("g")
j = B("j")
m = C("m")

a.t = n
a.s = g
n.y = a
n.o = a
g.q = m
g.s = a
g.o = a
j.y = a
j.o = a
m.q = g
m.s = a
m.o = a
assert a.s.s.t.o.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.s: C = None
        self.txt = txt

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

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

a = A("a")
n = B("n")
g = C("g")
j = B("j")
m = C("m")

a.t = n
a.s = g
n.y = a
n.o = a
g.q = m
g.s = a
g.o = a
j.y = a
j.o = a
m.q = g
m.s = a
m.o = a
assert a.s.s.t.o.txt == "a"