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

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

b = A("b")
n = B("n")
f = B("f")

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

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

b = A("b")
n = B("n")
f = B("f")

b.s = n
b.w = f
n.p = b
n.s = f
f.p = b
f.s = n
assert b.s.p.s.txt == "n"