class A:
    def __init__(self, txt: str):
        self.q: A = 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")
b = B("b")
j = A("j")
g = B("g")

m.q = j
m.s = j
b.q = m
j.q = m
j.s = m
g.q = j
assert j.s.q.s.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = 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")
b = B("b")
j = A("j")
g = B("g")

m.q = j
m.s = j
b.q = m
j.q = m
j.s = m
g.q = j
assert j.s.q.s.txt == "m"