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

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

m = A("m")
a = B("a")
j = B("j")
i = A("i")
l = B("l")

m.u = a
m.w = i
a.x = m
a.q = i
j.x = m
j.q = i
i.u = a
i.w = m
l.x = i
l.q = m
assert i.w.u.q.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.w: A = None
        self.txt = txt

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

m = A("m")
a = B("a")
j = B("j")
i = A("i")
l = B("l")

m.u = a
m.w = i
a.x = m
a.q = i
j.x = m
j.q = i
i.u = a
i.w = m
l.x = i
l.q = m
assert i.w.u.q.txt == "i"