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

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

a = A("a")
k = B("k")
l = B("l")

a.w = k
k.r = a
k.o = l
l.r = a
l.o = k
assert l.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

a = A("a")
k = B("k")
l = B("l")

a.w = k
k.r = a
k.o = l
l.r = a
l.o = k
assert l.o.o.o.txt == "k"