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

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

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

f = A("f")
h = B("h")
i = C("i")

f.s = i
h.p = f
h.r = f
h.x = f
i.s = h
assert h.p.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.txt = txt

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

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

f = A("f")
h = B("h")
i = C("i")

f.s = i
h.p = f
h.r = f
h.x = f
i.s = h
assert h.p.s.s.txt == "h"