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

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

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

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

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

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

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

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

c.s = m
m.r = e
m.p = c
e.x = m
e.t = j
e.u = g
j.r = e
j.p = c
g.x = m
g.t = m
g.u = e
assert c.s.p.s.p.txt == "c"