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

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

e = A("e")
i = B("i")
g = A("g")

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

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

e = A("e")
i = B("i")
g = A("g")

e.u = g
e.q = i
i.z = e
i.u = g
g.u = e
g.q = i
assert e.q.z.q.txt == "i"