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

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

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

h = A("h")
n = B("n")
i = C("i")
b = B("b")

h.p = n
n.y = h
n.w = h
i.p = n
i.y = n
i.s = h
b.y = h
b.w = h
assert i.s.p.y.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

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

h = A("h")
n = B("n")
i = C("i")
b = B("b")

h.p = n
n.y = h
n.w = h
i.p = n
i.y = n
i.s = h
b.y = h
b.w = h
assert i.s.p.y.txt == "h"