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

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

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

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

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

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

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