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

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

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

g = A("g")
e = B("e")
m = C("m")
a = A("a")
c = B("c")

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

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

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

g = A("g")
e = B("e")
m = C("m")
a = A("a")
c = B("c")

g.s = a
e.u = g
e.q = a
e.s = c
m.p = c
m.r = a
a.s = g
c.u = a
c.q = g
c.s = e
assert a.s.s.s.s.txt == "a"