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

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

k = A("k")
d = B("d")
c = A("c")
l = B("l")
b = B("b")

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

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

k = A("k")
d = B("d")
c = A("c")
l = B("l")
b = B("b")

k.r = c
d.s = b
d.w = k
c.r = k
l.s = b
l.w = k
b.s = d
b.w = k
assert l.s.w.r.r.r.txt == "c"