class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.q: 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.p: B = None
        self.txt = txt

j = A("j")
c = B("c")
i = C("i")

j.r = c
j.q = c
c.s = j
i.p = c
assert c.s.r.s.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.q: 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.p: B = None
        self.txt = txt

j = A("j")
c = B("c")
i = C("i")

j.r = c
j.q = c
c.s = j
i.p = c
assert c.s.r.s.txt == "j"