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

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

l = A("l")
d = B("d")
g = A("g")
b = B("b")

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

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

l = A("l")
d = B("d")
g = A("g")
b = B("b")

l.s = g
d.w = l
g.s = l
b.w = l
assert d.w.s.s.s.txt == "g"