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

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

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

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

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

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

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