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

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

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

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

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

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

l.w = j
l.q = a
a.w = j
j.w = a
assert a.w.w.w.txt == "j"