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

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

d = A("d")
f = B("f")
a = B("a")
b = A("b")
i = B("i")

d.s = a
d.r = b
f.w = b
a.w = d
b.s = a
b.r = d
i.w = b
assert f.w.s.w.s.w.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.r: A = None
        self.txt = txt

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

d = A("d")
f = B("f")
a = B("a")
b = A("b")
i = B("i")

d.s = a
d.r = b
f.w = b
a.w = d
b.s = a
b.r = d
i.w = b
assert f.w.s.w.s.w.txt == "d"