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

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

c = A("c")
h = B("h")
d = B("d")

c.s = d
h.w = c
h.p = c
d.w = c
d.p = c
assert h.p.s.w.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

c = A("c")
h = B("h")
d = B("d")

c.s = d
h.w = c
h.p = c
d.w = c
d.p = c
assert h.p.s.w.txt == "c"