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

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

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

e.q = i
e.z = m
m.u = e
i.q = e
i.z = b
b.u = i
assert i.q.z.u.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.z: B = None
        self.txt = txt

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

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

e.q = i
e.z = m
m.u = e
i.q = e
i.z = b
b.u = i
assert i.q.z.u.txt == "e"