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

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

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

c = A("c")
m = B("m")
a = C("a")
d = A("d")
j = B("j")
g = C("g")

c.u = m
m.s = d
a.q = m
a.p = m
a.o = j
d.u = m
j.s = c
g.q = j
g.p = j
g.o = m
assert m.s.u.s.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

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

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

c = A("c")
m = B("m")
a = C("a")
d = A("d")
j = B("j")
g = C("g")

c.u = m
m.s = d
a.q = m
a.p = m
a.o = j
d.u = m
j.s = c
g.q = j
g.p = j
g.o = m
assert m.s.u.s.u.txt == "m"