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

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

k = A("k")
f = B("f")
d = A("d")

k.r = d
k.w = d
f.p = k
f.s = k
d.r = k
d.w = k
assert d.w.w.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.w: A = None
        self.txt = txt

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

k = A("k")
f = B("f")
d = A("d")

k.r = d
k.w = d
f.p = k
f.s = k
d.r = k
d.w = k
assert d.w.w.r.txt == "k"