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

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

m = A("m")
b = B("b")
l = A("l")

m.q = l
m.x = b
b.y = l
l.q = m
l.x = b
assert m.q.q.x.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.x: B = None
        self.txt = txt

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

m = A("m")
b = B("b")
l = A("l")

m.q = l
m.x = b
b.y = l
l.q = m
l.x = b
assert m.q.q.x.txt == "b"