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

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

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

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

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

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

b.s = f
f.q = b
a.q = b
assert f.q.s.q.txt == "b"