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

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

m = A("m")
f = B("f")
e = B("e")
b = A("b")

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

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

m = A("m")
f = B("f")
e = B("e")
b = A("b")

m.s = f
m.q = b
f.t = b
f.v = e
e.t = m
e.v = f
b.s = e
b.q = m
assert b.s.t.q.s.txt == "e"