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

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

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

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

d.r = m
g.s = a
g.p = m
j.p = g
a.r = m
b.s = a
b.p = j
m.p = b
assert a.r.p.s.r.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

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

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

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

d.r = m
g.s = a
g.p = m
j.p = g
a.r = m
b.s = a
b.p = j
m.p = b
assert a.r.p.s.r.p.p.txt == "j"