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

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

m = A("m")
e = B("e")
k = A("k")

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

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

m = A("m")
e = B("e")
k = A("k")

m.t = e
m.s = k
e.q = m
k.t = e
k.s = m
assert m.t.q.s.txt == "k"