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

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

k = A("k")
b = B("b")
j = A("j")

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

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

k = A("k")
b = B("b")
j = A("j")

k.w = j
k.s = b
b.p = j
j.w = k
j.s = b
assert b.p.w.w.txt == "j"