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

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

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

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

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

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

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